chat / app.py
JuanMa360's picture
bugfix: components
b06e2c3
raw
history blame
1.78 kB
import time
import gradio as gr
import requests
import json
def slow_api_response(message, history, property_id="c0ced2220b87fc23762facf617157a4f"):
url = "https://data-monopolio.dev.dd360.mx/ai-assistant/v1"
payload = json.dumps({
"query": message,
"sessionId": "12345",
"numMessages": "3",
"userId": "user-01",
"property_id": property_id #"c0ced2220b87fc23762facf617157a4f"
})
headers = {
'Content-Type': 'application/json'
}
try:
response = requests.request("POST", url, headers=headers, data=payload)
if response.status_code == 500: # Verifica si hay un error interno del servidor
yield "Error: No existe el ID de la propiedad."
else:
api_response = response.text
api_response = api_response.encode().decode('unicode_escape')
for i in range(len(api_response)):
time.sleep(0.05)
yield api_response[:i + 1]
except requests.RequestException as e:
yield f"Error: {str(e)}"
property_id_input = gr.Textbox(label="Property ID", placeholder="Ingresa el ID de la propiedad")
examples = [
["hola", "c0ced2220b87fc23762facf617157a4f"],
["me gustaria mas informacion de la casa en venta", "c0ced2220b87fc23762facf617157a4f"],
["acepta mascotas?", "c0ced2220b87fc23762facf617157a4f"]
]
demo = gr.ChatInterface(fn=slow_api_response,
title="AI Assistant",
additional_inputs=[property_id_input],
description="Esta app simula una conversación con un asistente virtual que conoce una propiedad.",
examples=examples
).launch()