Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -529,19 +529,22 @@ def answer_finance_question(question: str, analysis_state: dict) -> str:
|
|
| 529 |
|
| 530 |
|
| 531 |
def chat_with_finance_agent(user_message, chat_history, analysis_state):
|
|
|
|
|
|
|
| 532 |
if not user_message or str(user_message).strip() == "":
|
| 533 |
return chat_history, ""
|
| 534 |
|
| 535 |
-
answer = answer_finance_question(user_message, analysis_state)
|
| 536 |
|
| 537 |
-
|
| 538 |
-
chat_history
|
|
|
|
| 539 |
|
| 540 |
return chat_history, ""
|
| 541 |
|
| 542 |
|
| 543 |
def clear_chat():
|
| 544 |
-
return []
|
| 545 |
|
| 546 |
|
| 547 |
# ---------------------------------------------------
|
|
@@ -592,19 +595,6 @@ def run_close_agent(actual_file, compare_file):
|
|
| 592 |
"management_notes": mgmt_notes
|
| 593 |
}
|
| 594 |
|
| 595 |
-
starter_chat = [
|
| 596 |
-
{
|
| 597 |
-
"role": "assistant",
|
| 598 |
-
"content": (
|
| 599 |
-
"Analysis is ready. Ask me something like:\n"
|
| 600 |
-
"- Why did EBITDA drop?\n"
|
| 601 |
-
"- What are the top 3 risks?\n"
|
| 602 |
-
"- Which metrics are unfavorable?\n"
|
| 603 |
-
"- Summarize this for leadership"
|
| 604 |
-
)
|
| 605 |
-
}
|
| 606 |
-
]
|
| 607 |
-
|
| 608 |
return (
|
| 609 |
variance_display,
|
| 610 |
insight_text,
|
|
@@ -615,7 +605,7 @@ def run_close_agent(actual_file, compare_file):
|
|
| 615 |
variance_chart,
|
| 616 |
actual_compare_chart,
|
| 617 |
analysis_state,
|
| 618 |
-
|
| 619 |
)
|
| 620 |
|
| 621 |
except Exception as e:
|
|
@@ -693,7 +683,7 @@ footer {
|
|
| 693 |
# ---------------------------------------------------
|
| 694 |
# UI
|
| 695 |
# ---------------------------------------------------
|
| 696 |
-
with gr.Blocks(
|
| 697 |
analysis_state = gr.State({})
|
| 698 |
gr.HTML(
|
| 699 |
"""
|
|
@@ -739,22 +729,32 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(), title=APP_TITLE) as demo:
|
|
| 739 |
actual_compare_chart = gr.Plot(label="Actual vs Comparison")
|
| 740 |
|
| 741 |
with gr.Tab("Ask Finance Agent"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 742 |
chatbot = gr.Chatbot(
|
| 743 |
label="Finance Agent Conversation",
|
| 744 |
height=420
|
| 745 |
)
|
|
|
|
| 746 |
finance_question = gr.Textbox(
|
| 747 |
label="Ask a finance question",
|
| 748 |
placeholder="Example: Why did EBITDA drop?",
|
| 749 |
lines=2
|
| 750 |
)
|
|
|
|
| 751 |
with gr.Row():
|
| 752 |
ask_btn = gr.Button("Ask Finance Agent", variant="primary")
|
| 753 |
clear_btn = gr.Button("Clear Chat")
|
| 754 |
|
| 755 |
-
with gr.Tab("Agent Trace"):
|
| 756 |
-
trace_box = gr.Code(label="Execution Trace", language="json")
|
| 757 |
-
|
| 758 |
run_btn.click(
|
| 759 |
fn=run_close_agent,
|
| 760 |
inputs=[actual_file, compare_file],
|
|
@@ -787,7 +787,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(), title=APP_TITLE) as demo:
|
|
| 787 |
clear_btn.click(
|
| 788 |
fn=clear_chat,
|
| 789 |
inputs=[],
|
| 790 |
-
outputs=[chatbot]
|
| 791 |
)
|
| 792 |
|
| 793 |
sample_actual_btn.click(
|
|
@@ -802,4 +802,4 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft(), title=APP_TITLE) as demo:
|
|
| 802 |
outputs=[sample_budget_output]
|
| 803 |
)
|
| 804 |
|
| 805 |
-
demo.launch()
|
|
|
|
| 529 |
|
| 530 |
|
| 531 |
def chat_with_finance_agent(user_message, chat_history, analysis_state):
|
| 532 |
+
chat_history = chat_history or []
|
| 533 |
+
|
| 534 |
if not user_message or str(user_message).strip() == "":
|
| 535 |
return chat_history, ""
|
| 536 |
|
| 537 |
+
answer = answer_finance_question(str(user_message).strip(), analysis_state)
|
| 538 |
|
| 539 |
+
# Gradio-safe tuple format
|
| 540 |
+
chat_history = list(chat_history)
|
| 541 |
+
chat_history.append((str(user_message), str(answer)))
|
| 542 |
|
| 543 |
return chat_history, ""
|
| 544 |
|
| 545 |
|
| 546 |
def clear_chat():
|
| 547 |
+
return [], ""
|
| 548 |
|
| 549 |
|
| 550 |
# ---------------------------------------------------
|
|
|
|
| 595 |
"management_notes": mgmt_notes
|
| 596 |
}
|
| 597 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 598 |
return (
|
| 599 |
variance_display,
|
| 600 |
insight_text,
|
|
|
|
| 605 |
variance_chart,
|
| 606 |
actual_compare_chart,
|
| 607 |
analysis_state,
|
| 608 |
+
[]
|
| 609 |
)
|
| 610 |
|
| 611 |
except Exception as e:
|
|
|
|
| 683 |
# ---------------------------------------------------
|
| 684 |
# UI
|
| 685 |
# ---------------------------------------------------
|
| 686 |
+
with gr.Blocks(title=APP_TITLE) as demo:
|
| 687 |
analysis_state = gr.State({})
|
| 688 |
gr.HTML(
|
| 689 |
"""
|
|
|
|
| 729 |
actual_compare_chart = gr.Plot(label="Actual vs Comparison")
|
| 730 |
|
| 731 |
with gr.Tab("Ask Finance Agent"):
|
| 732 |
+
gr.Markdown(
|
| 733 |
+
"""
|
| 734 |
+
**Ask questions like:**
|
| 735 |
+
- Why did EBITDA drop?
|
| 736 |
+
- What are the top 3 risks?
|
| 737 |
+
- Which metrics are unfavorable?
|
| 738 |
+
- Summarize this for leadership
|
| 739 |
+
- What should finance focus on first?
|
| 740 |
+
"""
|
| 741 |
+
)
|
| 742 |
+
|
| 743 |
chatbot = gr.Chatbot(
|
| 744 |
label="Finance Agent Conversation",
|
| 745 |
height=420
|
| 746 |
)
|
| 747 |
+
|
| 748 |
finance_question = gr.Textbox(
|
| 749 |
label="Ask a finance question",
|
| 750 |
placeholder="Example: Why did EBITDA drop?",
|
| 751 |
lines=2
|
| 752 |
)
|
| 753 |
+
|
| 754 |
with gr.Row():
|
| 755 |
ask_btn = gr.Button("Ask Finance Agent", variant="primary")
|
| 756 |
clear_btn = gr.Button("Clear Chat")
|
| 757 |
|
|
|
|
|
|
|
|
|
|
| 758 |
run_btn.click(
|
| 759 |
fn=run_close_agent,
|
| 760 |
inputs=[actual_file, compare_file],
|
|
|
|
| 787 |
clear_btn.click(
|
| 788 |
fn=clear_chat,
|
| 789 |
inputs=[],
|
| 790 |
+
outputs=[chatbot, finance_question]
|
| 791 |
)
|
| 792 |
|
| 793 |
sample_actual_btn.click(
|
|
|
|
| 802 |
outputs=[sample_budget_output]
|
| 803 |
)
|
| 804 |
|
| 805 |
+
demo.launch(css=custom_css, theme=gr.themes.Soft())
|