Upload 2 files
Browse files- interfaces/__init__.py +4 -0
- interfaces/interface.py +48 -0
interfaces/__init__.py
CHANGED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# interfaces/__init__.py
|
| 2 |
+
from .interface import create_interface
|
| 3 |
+
|
| 4 |
+
__all__ = ["create_interface"]
|
interfaces/interface.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from langchain_core.messages import HumanMessage, messages_to_dict
|
| 3 |
+
from langgraph.graph import StateGraph, END
|
| 4 |
+
from agents.agents_nodes import agent_node, format_output, tool_node
|
| 5 |
+
from utils.state_utils import AgentState
|
| 6 |
+
|
| 7 |
+
def create_interface():
|
| 8 |
+
|
| 9 |
+
graph = StateGraph(AgentState)
|
| 10 |
+
graph.add_node("agent", agent_node)
|
| 11 |
+
graph.add_node("tool", tool_node)
|
| 12 |
+
graph.add_node("format", format_output)
|
| 13 |
+
|
| 14 |
+
graph.set_entry_point("agent")
|
| 15 |
+
graph.add_edge("agent", "tool")
|
| 16 |
+
graph.add_edge("tool", "format")
|
| 17 |
+
graph.add_edge("format", END)
|
| 18 |
+
|
| 19 |
+
app = graph.compile()
|
| 20 |
+
|
| 21 |
+
def process_query(query: str) -> dict:
|
| 22 |
+
try:
|
| 23 |
+
inputs = {"messages": [HumanMessage(content=query)]}
|
| 24 |
+
result = app.invoke(inputs)
|
| 25 |
+
return messages_to_dict(result['messages'])[2]['data']['content']
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return {"error": f"Execution error: {str(e)}"}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
with gr.Blocks(title="Time Value of Money Calculator") as interface:
|
| 31 |
+
gr.Markdown("## Time Value of Money Calculator")
|
| 32 |
+
gr.Markdown("Enter natural language queries about present/future value calculations")
|
| 33 |
+
|
| 34 |
+
with gr.Row():
|
| 35 |
+
input_text = gr.Textbox(
|
| 36 |
+
label="Financial Question",
|
| 37 |
+
placeholder="E.g.: Present value of $3000 in 5 years at 8% interest?",
|
| 38 |
+
lines=3
|
| 39 |
+
)
|
| 40 |
+
output_json = gr.JSON(label="Result")
|
| 41 |
+
|
| 42 |
+
submit_btn = gr.Button("Calculate")
|
| 43 |
+
submit_btn.click(
|
| 44 |
+
fn=process_query,
|
| 45 |
+
inputs=input_text,
|
| 46 |
+
outputs=output_json
|
| 47 |
+
)
|
| 48 |
+
return interface
|