Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 18 |
-
|
| 19 |
-
return response[0]['text'] if response else "I didn't understand that."
|
| 20 |
|
| 21 |
-
def
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
iface = gr.Interface(fn=
|
| 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 |
|