|
import time |
|
import gradio as gr |
|
import requests |
|
import json |
|
|
|
|
|
def slow_api_response(message, history): |
|
url = "https://data-monopolio.dev.dd360.mx/ai-assistant/v1" |
|
|
|
|
|
payload = json.dumps({ |
|
"query": message, |
|
"sessionId": "12345", |
|
"numMessages": "1", |
|
"userId": "user-01", |
|
"property_id": "c0ced2220b87fc23762facf617157a4f" |
|
}) |
|
|
|
headers = { |
|
'Content-Type': 'application/json' |
|
} |
|
|
|
try: |
|
|
|
response = requests.request("POST", url, headers=headers, data=payload) |
|
api_response = response.text |
|
|
|
|
|
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)}" |
|
|
|
|
|
demo = gr.ChatInterface(fn=slow_api_response) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|