Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -612,7 +612,7 @@ def finalize_report(state: ResearchGraphState):
|
|
612 |
final_report += "\n\n## Sources\n" + sources
|
613 |
return {"final_report": final_report}
|
614 |
|
615 |
-
|
616 |
builder = StateGraph(ResearchGraphState)
|
617 |
builder.add_node("create_analysts", create_analysts)
|
618 |
builder.add_node("human_feedback", human_feedback)
|
@@ -622,7 +622,6 @@ builder.add_node("write_introduction",write_introduction)
|
|
622 |
builder.add_node("write_conclusion",write_conclusion)
|
623 |
builder.add_node("finalize_report",finalize_report)
|
624 |
|
625 |
-
# Logic
|
626 |
builder.add_edge(START, "create_analysts")
|
627 |
builder.add_edge("create_analysts", "human_feedback")
|
628 |
builder.add_conditional_edges("human_feedback", initiate_all_interviews, ["create_analysts", "conduct_interview"])
|
@@ -632,7 +631,7 @@ builder.add_edge("conduct_interview", "write_conclusion")
|
|
632 |
builder.add_edge(["write_conclusion", "write_report", "write_introduction"], "finalize_report")
|
633 |
builder.add_edge("finalize_report", END)
|
634 |
|
635 |
-
|
636 |
memory = MemorySaver()
|
637 |
graph = builder.compile(interrupt_before=['human_feedback'], checkpointer=memory)
|
638 |
|
@@ -694,10 +693,9 @@ def process_feedback(topic, max_analysts, feedback, thread_id):
|
|
694 |
return "\n\n".join(analyst_info), thread_id, gr.update(visible=True)
|
695 |
return "No new analysts generated. Please try again with different feedback.", thread_id, gr.update(visible=True)
|
696 |
else:
|
697 |
-
# 繼續研究過程
|
698 |
graph.update_state(thread, {"human_analyst_feedback": None}, as_node="human_feedback")
|
699 |
for event in graph.stream(None, thread, stream_mode="updates"):
|
700 |
-
pass
|
701 |
|
702 |
final_state = graph.get_state(thread)
|
703 |
report = final_state.values.get('final_report')
|
@@ -708,11 +706,7 @@ def process_feedback(topic, max_analysts, feedback, thread_id):
|
|
708 |
except Exception as e:
|
709 |
return f"An error occurred: {str(e)}", thread_id, gr.update(visible=True)
|
710 |
|
711 |
-
# 在文件頂部加以下導入
|
712 |
-
from gradio.themes.utils import colors
|
713 |
-
from gradio.themes import Base
|
714 |
|
715 |
-
# 在 demo 定義之前添加以下主題定義
|
716 |
theme = Base(
|
717 |
primary_hue=colors.blue,
|
718 |
secondary_hue=colors.slate,
|
@@ -729,7 +723,6 @@ theme = Base(
|
|
729 |
block_shadow="0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)",
|
730 |
)
|
731 |
|
732 |
-
# 修改 Gradio 介面定義
|
733 |
with gr.Blocks(theme=theme, css="footer {visibility: hidden}") as demo:
|
734 |
gr.Markdown(
|
735 |
"""
|
@@ -743,8 +736,6 @@ with gr.Blocks(theme=theme, css="footer {visibility: hidden}") as demo:
|
|
743 |
In the end, you'll get a well-rounded report that brings together all the key findings.
|
744 |
|
745 |
[📊 View the Research Team workflow diagram](https://huggingface.co/spaces/jc132/Research_Team/resolve/main/agents.jpg)
|
746 |
-
|
747 |
-
[🔍 View a sample run trace on LangSmith](https://smith.langchain.com/public/02b56050-e88b-412b-a966-ee2a4436c71e/r)
|
748 |
"""
|
749 |
)
|
750 |
|
@@ -783,5 +774,8 @@ with gr.Blocks(theme=theme, css="footer {visibility: hidden}") as demo:
|
|
783 |
inputs=[topic, max_analysts, feedback, thread_id],
|
784 |
outputs=[output, thread_id, feedback_row])
|
785 |
|
|
|
|
|
|
|
786 |
if __name__ == "__main__":
|
787 |
demo.launch()
|
|
|
612 |
final_report += "\n\n## Sources\n" + sources
|
613 |
return {"final_report": final_report}
|
614 |
|
615 |
+
|
616 |
builder = StateGraph(ResearchGraphState)
|
617 |
builder.add_node("create_analysts", create_analysts)
|
618 |
builder.add_node("human_feedback", human_feedback)
|
|
|
622 |
builder.add_node("write_conclusion",write_conclusion)
|
623 |
builder.add_node("finalize_report",finalize_report)
|
624 |
|
|
|
625 |
builder.add_edge(START, "create_analysts")
|
626 |
builder.add_edge("create_analysts", "human_feedback")
|
627 |
builder.add_conditional_edges("human_feedback", initiate_all_interviews, ["create_analysts", "conduct_interview"])
|
|
|
631 |
builder.add_edge(["write_conclusion", "write_report", "write_introduction"], "finalize_report")
|
632 |
builder.add_edge("finalize_report", END)
|
633 |
|
634 |
+
|
635 |
memory = MemorySaver()
|
636 |
graph = builder.compile(interrupt_before=['human_feedback'], checkpointer=memory)
|
637 |
|
|
|
693 |
return "\n\n".join(analyst_info), thread_id, gr.update(visible=True)
|
694 |
return "No new analysts generated. Please try again with different feedback.", thread_id, gr.update(visible=True)
|
695 |
else:
|
|
|
696 |
graph.update_state(thread, {"human_analyst_feedback": None}, as_node="human_feedback")
|
697 |
for event in graph.stream(None, thread, stream_mode="updates"):
|
698 |
+
pass
|
699 |
|
700 |
final_state = graph.get_state(thread)
|
701 |
report = final_state.values.get('final_report')
|
|
|
706 |
except Exception as e:
|
707 |
return f"An error occurred: {str(e)}", thread_id, gr.update(visible=True)
|
708 |
|
|
|
|
|
|
|
709 |
|
|
|
710 |
theme = Base(
|
711 |
primary_hue=colors.blue,
|
712 |
secondary_hue=colors.slate,
|
|
|
723 |
block_shadow="0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)",
|
724 |
)
|
725 |
|
|
|
726 |
with gr.Blocks(theme=theme, css="footer {visibility: hidden}") as demo:
|
727 |
gr.Markdown(
|
728 |
"""
|
|
|
736 |
In the end, you'll get a well-rounded report that brings together all the key findings.
|
737 |
|
738 |
[📊 View the Research Team workflow diagram](https://huggingface.co/spaces/jc132/Research_Team/resolve/main/agents.jpg)
|
|
|
|
|
739 |
"""
|
740 |
)
|
741 |
|
|
|
774 |
inputs=[topic, max_analysts, feedback, thread_id],
|
775 |
outputs=[output, thread_id, feedback_row])
|
776 |
|
777 |
+
|
778 |
+
|
779 |
+
|
780 |
if __name__ == "__main__":
|
781 |
demo.launch()
|