Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import asyncio
|
| 3 |
from agents import build_graph
|
| 4 |
|
| 5 |
-
# Build + compile once at import time
|
| 6 |
graph = build_graph()
|
| 7 |
|
| 8 |
async def run_book_recommender(user_input):
|
| 9 |
-
# 1) build initial state
|
| 10 |
initial_state = {"user_input": user_input}
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
#
|
| 16 |
recs = final_state.get("final_recommendations", [])
|
| 17 |
reasoning = final_state.get("final_reasoning", "")
|
| 18 |
|
| 19 |
-
# 4) format for display
|
| 20 |
recs_text = "\n\n".join(
|
| 21 |
f"๐ {r['title']}\n๐ {r.get('link','')}\n๐ก {r.get('reason','')}"
|
| 22 |
for r in recs
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from agents import build_graph
|
| 3 |
|
|
|
|
| 4 |
graph = build_graph()
|
| 5 |
|
| 6 |
async def run_book_recommender(user_input):
|
|
|
|
| 7 |
initial_state = {"user_input": user_input}
|
| 8 |
|
| 9 |
+
final_state = None
|
| 10 |
+
# .astream yields after each node runs
|
| 11 |
+
async for state in graph.astream(initial_state):
|
| 12 |
+
final_state = state
|
| 13 |
|
| 14 |
+
# now state after the last node is in final_state
|
| 15 |
recs = final_state.get("final_recommendations", [])
|
| 16 |
reasoning = final_state.get("final_reasoning", "")
|
| 17 |
|
|
|
|
| 18 |
recs_text = "\n\n".join(
|
| 19 |
f"๐ {r['title']}\n๐ {r.get('link','')}\n๐ก {r.get('reason','')}"
|
| 20 |
for r in recs
|