File size: 1,700 Bytes
1741cfe
 
 
 
 
 
 
60a9916
1741cfe
 
de78c81
 
 
60a9916
 
1741cfe
 
 
 
 
 
 
 
 
d59f3e4
 
1741cfe
 
 
60a9916
1741cfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f183d0d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import gradio as gr
from langchain_core.messages import HumanMessage, messages_to_dict
from langgraph.graph import StateGraph, END
from agents.agents_nodes import agent_node, format_output, tool_node
from utils.state_utils import AgentState

def create_interface():

    graph = StateGraph(AgentState)
    graph.add_node("agent", agent_node)
    graph.add_node("tool", tool_node)
    graph.add_node("format", format_output)
    
    graph.set_entry_point("agent")
    graph.add_edge("agent", "tool")
    graph.add_edge("tool", "format")
    graph.add_edge("format", END)
    
    app = graph.compile()

    def process_query(query: str) -> dict:
        try:
            inputs = {"messages": [HumanMessage(content=query)]}
            result = app.invoke(inputs)  
            # return messages_to_dict(result['messages'])[2]['data']['content']
            return result
        except Exception as e:
            return {"error": f"Execution error: {str(e)}"}


    with gr.Blocks(title="Time Value of Money Calculator") as interface:
        gr.Markdown("##  Time Value of Money Calculator")
        gr.Markdown("Enter natural language queries about present/future value calculations")
        
        with gr.Row():
            input_text = gr.Textbox(
                label="Financial Question",
                placeholder="E.g.: Present value of $3000 in 5 years at 8% interest?",
                lines=3
            )
            output_json = gr.JSON(label="Result")  
        
        submit_btn = gr.Button("Calculate")
        submit_btn.click(
            fn=process_query,       
            inputs=input_text,      
            outputs=output_json     
        )
    return interface