krrishkh12 commited on
Commit
b5ef678
·
verified ·
1 Parent(s): d053f1f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -39
app.py CHANGED
@@ -1,39 +0,0 @@
1
- import gradio as gr
2
- from main import api as fastapi_app
3
- from main import invoke_agent, QueryRequest
4
-
5
- # This function is designed to accept ONE argument: a list of messages.
6
- def get_agent_response(messages: list):
7
- """
8
- This function is called by the Gradio UI.
9
- 'messages' is a list of dictionaries in the OpenAI format.
10
- e.g., [{"role": "user", "content": "Hello!"}]
11
- """
12
- # The message list from Gradio is already in the correct format for our backend
13
- request = QueryRequest(messages=messages)
14
-
15
- try:
16
- # Call the invoke_agent function directly
17
- response_data = invoke_agent(request)
18
- # Return the content string for Gradio to display
19
- return response_data["response"]
20
- except Exception as e:
21
- print(f"Error calling agent logic: {e}")
22
- return "An error occurred while processing your request."
23
-
24
- # This component is configured to SEND ONE argument because of type="messages"
25
- chatbot_ui = gr.ChatInterface(
26
- fn=get_agent_response,
27
- title="Sarvam AI Agent",
28
- description="Ask me about horoscopes, holidays, and more!",
29
- # THIS LINE IS THE FIX. It makes the component and function match.
30
- type="messages",
31
- examples=[
32
- "What is the horoscope for Leo today?",
33
- "Tell me the panchang for today",
34
- "What are the Indian holidays in 2025?"
35
- ]
36
- )
37
-
38
- # Mount the Gradio UI onto the FastAPI backend
39
- app = gr.mount_gradio_app(fastapi_app, chatbot_ui, path="/")