Spaces:
Paused
Paused
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -235,7 +235,7 @@ EXAMPLES = [
|
|
| 235 |
"Propose a novel hypothesis for self-healing biopolymer composites.",
|
| 236 |
]
|
| 237 |
|
| 238 |
-
with gr.Blocks(
|
| 239 |
gr.Markdown(
|
| 240 |
"""
|
| 241 |
# 🧠 Graph-PrefLexOR: Graph-Native Scientific Reasoning
|
|
@@ -283,11 +283,21 @@ with gr.Blocks(css=CSS) as demo:
|
|
| 283 |
elem_id="graph-panel",
|
| 284 |
)
|
| 285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
gr.Examples(
|
| 287 |
examples=EXAMPLES,
|
| 288 |
inputs=msg_input,
|
| 289 |
outputs=[chatbot, graph_output],
|
| 290 |
-
fn=
|
| 291 |
cache_examples=False,
|
| 292 |
run_on_click=True,
|
| 293 |
)
|
|
@@ -311,9 +321,10 @@ with gr.Blocks(css=CSS) as demo:
|
|
| 311 |
updated = history + [{"role": "assistant", "content": text}]
|
| 312 |
yield updated, graph_html
|
| 313 |
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
|
|
|
| 317 |
user_submit,
|
| 318 |
[msg_input, chatbot],
|
| 319 |
[msg_input, chatbot],
|
|
@@ -322,13 +333,14 @@ with gr.Blocks(css=CSS) as demo:
|
|
| 322 |
[chatbot, max_tokens, temperature, top_p],
|
| 323 |
[chatbot, graph_output],
|
| 324 |
)
|
|
|
|
| 325 |
|
| 326 |
clear_btn.click(
|
| 327 |
lambda: ([], "<p style='color:#888;text-align:center;padding:40px;'>The extracted knowledge graph will appear here after generation.</p>"),
|
| 328 |
None,
|
| 329 |
[chatbot, graph_output],
|
| 330 |
)
|
| 331 |
-
stop_btn.click(None, None, None, cancels=
|
| 332 |
|
| 333 |
|
| 334 |
-
demo.launch(theme=gr.themes.Citrus(), mcp_server=True)
|
|
|
|
| 235 |
"Propose a novel hypothesis for self-healing biopolymer composites.",
|
| 236 |
]
|
| 237 |
|
| 238 |
+
with gr.Blocks() as demo:
|
| 239 |
gr.Markdown(
|
| 240 |
"""
|
| 241 |
# 🧠 Graph-PrefLexOR: Graph-Native Scientific Reasoning
|
|
|
|
| 283 |
elem_id="graph-panel",
|
| 284 |
)
|
| 285 |
|
| 286 |
+
def run_example(message):
|
| 287 |
+
"""Wrapper for gr.Examples: run generate with defaults, return chat history + graph."""
|
| 288 |
+
for text, graph_html in generate(message, [], 8192, 0.2, 0.95):
|
| 289 |
+
pass
|
| 290 |
+
history = [
|
| 291 |
+
{"role": "user", "content": message},
|
| 292 |
+
{"role": "assistant", "content": text},
|
| 293 |
+
]
|
| 294 |
+
return history, graph_html
|
| 295 |
+
|
| 296 |
gr.Examples(
|
| 297 |
examples=EXAMPLES,
|
| 298 |
inputs=msg_input,
|
| 299 |
outputs=[chatbot, graph_output],
|
| 300 |
+
fn=run_example,
|
| 301 |
cache_examples=False,
|
| 302 |
run_on_click=True,
|
| 303 |
)
|
|
|
|
| 321 |
updated = history + [{"role": "assistant", "content": text}]
|
| 322 |
yield updated, graph_html
|
| 323 |
|
| 324 |
+
submit_events = [send_btn.click, msg_input.submit]
|
| 325 |
+
cancel_targets = []
|
| 326 |
+
for evt in submit_events:
|
| 327 |
+
click_event = evt(
|
| 328 |
user_submit,
|
| 329 |
[msg_input, chatbot],
|
| 330 |
[msg_input, chatbot],
|
|
|
|
| 333 |
[chatbot, max_tokens, temperature, top_p],
|
| 334 |
[chatbot, graph_output],
|
| 335 |
)
|
| 336 |
+
cancel_targets.append(click_event)
|
| 337 |
|
| 338 |
clear_btn.click(
|
| 339 |
lambda: ([], "<p style='color:#888;text-align:center;padding:40px;'>The extracted knowledge graph will appear here after generation.</p>"),
|
| 340 |
None,
|
| 341 |
[chatbot, graph_output],
|
| 342 |
)
|
| 343 |
+
stop_btn.click(None, None, None, cancels=cancel_targets)
|
| 344 |
|
| 345 |
|
| 346 |
+
demo.launch(theme=gr.themes.Citrus(), css=CSS, mcp_server=True)
|