File size: 1,782 Bytes
42f970b
c732a18
ab558ef
 
c732a18
a0245a6
ab558ef
4eaf1b2
ab558ef
 
 
da033a6
ab558ef
a0245a6
ab558ef
 
 
 
 
4eaf1b2
ab558ef
da033a6
ab558ef
b06e2c3
 
ab558ef
b06e2c3
 
 
 
 
 
 
c732a18
ab558ef
 
 
a0245a6
e0b6915
 
b06e2c3
 
e0b6915
da033a6
26325b4
da033a6
a0245a6
26325b4
e0b6915
da033a6
d5c9e08
f3ceb0f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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()