CoolFace
Apppublic

Shago/basic_engineering_economics_agent

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
interface.py50 linesDownload Raw Back to interfaces
1import gradio as gr2from langchain_core.messages import HumanMessage, messages_to_dict3from langgraph.graph import StateGraph, END4from agents.agents_nodes import agent_node, format_output, tool_node5from utils.state_utils import AgentState6 7def 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            return result27        except Exception as e:28            return {"error": f"Execution error: {str(e)}"}29 30 31    with gr.Blocks(title="Time Value of Money Calculator") as interface:32        gr.Markdown("##  Time Value of Money Calculator")33        gr.Markdown("Enter natural language queries about present/future value calculations")34        35        with gr.Row():36            input_text = gr.Textbox(37                label="Financial Question",38                placeholder="E.g.: Present value of $3000 in 5 years at 8% interest?",39                lines=340            )41            output_json = gr.JSON(label="Result")  42        43        submit_btn = gr.Button("Calculate")44        submit_btn.click(45            fn=process_query,       46            inputs=input_text,      47            outputs=output_json     48        )49    return interface50