Skip to content

Commit 366a65e

Browse files
fix: relocate progress bar
1 parent 2b420b0 commit 366a65e

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

graphgen/operators/extract_kg.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,11 @@ async def _process_single_content(chunk: Chunk, max_loop: int = 3):
110110
unit="chunk",
111111
):
112112
try:
113-
results.append(await result)
114113
if progress_bar is not None:
115114
progress_bar(len(results) / chunk_number, desc="[3/4]Extracting entities and relationships from chunks")
115+
results.append(await result)
116+
if progress_bar is not None and len(results) == chunk_number:
117+
progress_bar(1, desc="[3/4]Extracting entities and relationships from chunks")
116118
except Exception as e: # pylint: disable=broad-except
117119
logger.error("Error occurred while extracting entities and relationships from chunks: %s", e)
118120

graphgen/operators/traverse_graph.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,11 @@ async def _process_single_batch(
294294
[_process_single_batch(batch) for batch in processing_batches]
295295
), total=len(processing_batches), desc="[4/4]Generating QAs"):
296296
try:
297-
results.update(await result)
298297
if progress_bar is not None:
299298
progress_bar(len(results) / len(processing_batches), desc="[4/4]Generating QAs")
299+
results.update(await result)
300+
if progress_bar is not None and len(results) == len(processing_batches):
301+
progress_bar(1, desc="[4/4]Generating QAs")
300302
except Exception as e: # pylint: disable=broad-except
301303
logger.error("Error occurred while generating QA: %s", e)
302304

@@ -401,9 +403,11 @@ async def _generate_question(
401403
desc="[4/4]Generating QAs"
402404
):
403405
try:
404-
results.update(await result)
405406
if progress_bar is not None:
406407
progress_bar(len(results) / len(tasks), desc="[4/4]Generating QAs")
408+
results.update(await result)
409+
if progress_bar is not None and len(results) == len(tasks):
410+
progress_bar(1, desc="[4/4]Generating QAs")
407411
except Exception as e: # pylint: disable=broad-except
408412
logger.error("Error occurred while generating QA: %s", e)
409413
return results
@@ -513,9 +517,11 @@ async def _process_single_batch(
513517
desc="[4/4]Generating QAs"
514518
):
515519
try:
516-
results.update(await result)
517520
if progress_bar is not None:
518521
progress_bar(len(results) / len(processing_batches), desc="[4/4]Generating QAs")
522+
results.update(await result)
523+
if progress_bar is not None and len(results) == len(processing_batches):
524+
progress_bar(1, desc="[4/4]Generating QAs")
519525
except Exception as e: # pylint: disable=broad-except
520526
logger.error("Error occurred while generating QA: %s", e)
521527
return results

0 commit comments

Comments
 (0)