Skip to content

Commit

Permalink
fix apache#176: refactor(demo) switched gr.Blocks() concurrency to gr…
Browse files Browse the repository at this point in the history
….Button() concurrency.
  • Loading branch information
Kryst4lDem0ni4s committed Mar 3, 2025
1 parent 418df29 commit 2e11b1f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 59 deletions.
116 changes: 58 additions & 58 deletions hugegraph-llm/src/hugegraph_llm/demo/rag_demo/rag_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,68 +128,68 @@ def create_rag_block():
gr.Markdown("""## 1. HugeGraph RAG Query""")
with gr.Row():
with gr.Column(scale=2):
with gr.Blocks().queue(max_size=20, default_concurrency_limit=5):
inp = gr.Textbox(value=prompt.default_question, label="Question", show_copy_button=True, lines=3)
# with gr.Blocks().queue(max_size=20, default_concurrency_limit=5):
inp = gr.Textbox(value=prompt.default_question, label="Question", show_copy_button=True, lines=3)

# TODO: Only support inline formula now. Should support block formula
gr.Markdown("Basic LLM Answer", elem_classes="output-box-label")
raw_out = gr.Markdown(elem_classes="output-box", show_copy_button=True,
latex_delimiters=[{"left": "$", "right": "$", "display": False}])
gr.Markdown("Vector-only Answer", elem_classes="output-box-label")
vector_only_out = gr.Markdown(elem_classes="output-box", show_copy_button=True,
latex_delimiters=[{"left": "$", "right": "$", "display": False}])
gr.Markdown("Graph-only Answer", elem_classes="output-box-label")
graph_only_out = gr.Markdown(elem_classes="output-box", show_copy_button=True,
latex_delimiters=[{"left": "$", "right": "$", "display": False}])
gr.Markdown("Graph-Vector Answer", elem_classes="output-box-label")
graph_vector_out = gr.Markdown(elem_classes="output-box", show_copy_button=True,
latex_delimiters=[{"left": "$", "right": "$", "display": False}])
# TODO: Only support inline formula now. Should support block formula
gr.Markdown("Basic LLM Answer", elem_classes="output-box-label")
raw_out = gr.Markdown(elem_classes="output-box", show_copy_button=True,
latex_delimiters=[{"left": "$", "right": "$", "display": False}])
gr.Markdown("Vector-only Answer", elem_classes="output-box-label")
vector_only_out = gr.Markdown(elem_classes="output-box", show_copy_button=True,
latex_delimiters=[{"left": "$", "right": "$", "display": False}])
gr.Markdown("Graph-only Answer", elem_classes="output-box-label")
graph_only_out = gr.Markdown(elem_classes="output-box", show_copy_button=True,
latex_delimiters=[{"left": "$", "right": "$", "display": False}])
gr.Markdown("Graph-Vector Answer", elem_classes="output-box-label")
graph_vector_out = gr.Markdown(elem_classes="output-box", show_copy_button=True,
latex_delimiters=[{"left": "$", "right": "$", "display": False}])

answer_prompt_input = gr.Textbox(
value=prompt.answer_prompt, label="Query Prompt", show_copy_button=True, lines=7
)
keywords_extract_prompt_input = gr.Textbox(
value=prompt.keywords_extract_prompt,
label="Keywords Extraction Prompt",
show_copy_button=True,
lines=7,
)

with gr.Column(scale=1):
with gr.Row():
raw_radio = gr.Radio(choices=[True, False], value=False, label="Basic LLM Answer")
vector_only_radio = gr.Radio(choices=[True, False], value=False, label="Vector-only Answer")
with gr.Row():
graph_only_radio = gr.Radio(choices=[True, False], value=True, label="Graph-only Answer")
graph_vector_radio = gr.Radio(choices=[True, False], value=False, label="Graph-Vector Answer")
answer_prompt_input = gr.Textbox(
value=prompt.answer_prompt, label="Query Prompt", show_copy_button=True, lines=7
)
keywords_extract_prompt_input = gr.Textbox(
value=prompt.keywords_extract_prompt,
label="Keywords Extraction Prompt",
show_copy_button=True,
lines=7,
)

def toggle_slider(enable):
return gr.update(interactive=enable)
with gr.Column(scale=1):
with gr.Row():
raw_radio = gr.Radio(choices=[True, False], value=False, label="Basic LLM Answer")
vector_only_radio = gr.Radio(choices=[True, False], value=False, label="Vector-only Answer")
with gr.Row():
graph_only_radio = gr.Radio(choices=[True, False], value=True, label="Graph-only Answer")
graph_vector_radio = gr.Radio(choices=[True, False], value=False, label="Graph-Vector Answer")

with gr.Column():
with gr.Row():
online_rerank = llm_settings.reranker_type
rerank_method = gr.Dropdown(
choices=["bleu", ("rerank (online)", "reranker")] if online_rerank else ["bleu"],
value="reranker" if online_rerank else "bleu",
label="Rerank method",
)
example_num = gr.Number(value=2, label="Template Num (0 to disable it) ", precision=0)
graph_ratio = gr.Slider(0, 1, 0.6, label="Graph Ratio", step=0.1, interactive=False)
def toggle_slider(enable):
return gr.update(interactive=enable)

graph_vector_radio.change(
toggle_slider, inputs=graph_vector_radio, outputs=graph_ratio
) # pylint: disable=no-member
near_neighbor_first = gr.Checkbox(
value=False,
label="Near neighbor first(Optional)",
info="One-depth neighbors > two-depth neighbors",
)
custom_related_information = gr.Text(
prompt.custom_rerank_info,
label="Query related information(Optional)",
with gr.Column():
with gr.Row():
online_rerank = llm_settings.reranker_type
rerank_method = gr.Dropdown(
choices=["bleu", ("rerank (online)", "reranker")] if online_rerank else ["bleu"],
value="reranker" if online_rerank else "bleu",
label="Rerank method",
)
btn = gr.Button("Answer Question", variant="primary")
example_num = gr.Number(value=2, label="Template Num (0 to disable it) ", precision=0)
graph_ratio = gr.Slider(0, 1, 0.6, label="Graph Ratio", step=0.1, interactive=False)

graph_vector_radio.change(
toggle_slider, inputs=graph_vector_radio, outputs=graph_ratio
) # pylint: disable=no-member
near_neighbor_first = gr.Checkbox(
value=False,
label="Near neighbor first(Optional)",
info="One-depth neighbors > two-depth neighbors",
)
custom_related_information = gr.Text(
prompt.custom_rerank_info,
label="Query related information(Optional)",
)
btn = gr.Button("Answer Question", variant="primary")

btn.click( # pylint: disable=no-member
fn=rag_answer,
Expand All @@ -208,8 +208,8 @@ def toggle_slider(enable):
example_num,
],
outputs=[raw_out, vector_only_out, graph_only_out, graph_vector_out],
# queue=True, # Enable queueing for this event
# concurrency_limit=5, # Maximum of 5 concurrent executions
queue=True, # Enable queueing for this event
concurrency_limit=5, # Maximum of 5 concurrent executions
concurrency_id="rag_answer_task"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __post_init__(self):
try:
traceback.print_exception(e)
self.gs_supported = False
except Exception as e:
except:
exc_type, exc_value, tb = sys.exc_info()
traceback.print_exception(exc_type, exc_value, tb)
log.warning(
Expand Down

0 comments on commit 2e11b1f

Please sign in to comment.