manasagangotri commited on
Commit
ec8aef1
·
verified ·
1 Parent(s): 24625cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -20
app.py CHANGED
@@ -1,27 +1,20 @@
1
 
2
 
3
- import gradio as gr
4
- from rasa.core.agent import Agent
5
- import asyncio
6
-
7
- # Load the trained Rasa model
8
- async def load_agent():
9
- return await Agent.load("models/20250212-134423-fundamental-ridge.tar.gz")
10
-
11
- agent = asyncio.run(load_agent())
12
-
13
-
14
-
15
 
 
 
16
 
17
- async def chat_with_bot(message):
18
- response = await agent.handle_text(message)
19
- return response[0]['text'] if response else "I didn't understand that."
20
 
21
- def chat(message):
22
- return asyncio.run(chat_with_bot(message))
 
 
 
 
23
 
24
- # Create Gradio UI
25
- iface = gr.Interface(fn=chat, inputs="text", outputs="text", title="WhizJuniors FAQ Chatbot")
26
- iface.launch()
27
 
 
1
 
2
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
+ import gradio as gr
5
+ import requests
6
 
7
+ # Hugging Face Space URL
8
+ RASA_URL = "http://localhost:5005/webhooks/rest/webhook"
 
9
 
10
+ def chat_with_bot(user_message):
11
+ response = requests.post(RASA_URL, json={"sender": "user", "message": user_message})
12
+ bot_reply = response.json()
13
+ if bot_reply:
14
+ return bot_reply[0]['text']
15
+ return "I didn't understand that."
16
 
17
+ # Gradio UI
18
+ iface = gr.Interface(fn=chat_with_bot, inputs="text", outputs="text", title="Chat with Rasa Bot")
19
+ iface.launch(server_name="0.0.0.0", server_port=7860)
20