Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
def respond(message, property_id: str = "a0de88a24c4e844d86f285d6abbd59d0"):
|
5 |
+
|
6 |
+
api_url = "https://data-monopolio.dev.dd360.mx/ai-assistant/v1"
|
7 |
+
|
8 |
+
data = {
|
9 |
+
"query": message,
|
10 |
+
"sessionId": "12345",
|
11 |
+
"numMessages": 1,
|
12 |
+
"userId": "user-01",
|
13 |
+
"property_id": property_id
|
14 |
+
}
|
15 |
+
|
16 |
+
try:
|
17 |
+
|
18 |
+
response = requests.post(api_url, json=data)
|
19 |
+
response.raise_for_status()
|
20 |
+
|
21 |
+
return response.json().get("response", "No response from API.")
|
22 |
+
except requests.RequestException as e:
|
23 |
+
return f"Error: {str(e)}"
|
24 |
+
|
25 |
+
demo = gr.Interface(
|
26 |
+
fn=respond,
|
27 |
+
inputs=[
|
28 |
+
gr.Textbox(label="Message", placeholder="Type your message here..."),
|
29 |
+
gr.Textbox(label="Property ID", placeholder="Provide property id...")
|
30 |
+
],
|
31 |
+
outputs="text",
|
32 |
+
)
|
33 |
+
|
34 |
+
if __name__ == "__main__":
|
35 |
+
demo.launch()
|