Spaces:
Build error
Build error
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
# Configuración de OpenAI
|
| 4 |
+
|
| 5 |
+
# Función para manejar el flujo de la conversación
|
| 6 |
+
def model(text, conversation):
|
| 7 |
+
url = "https://dev.apis.umasalud.com/ai/predoc"
|
| 8 |
+
|
| 9 |
+
# Payload (datos a enviar)
|
| 10 |
+
data = {
|
| 11 |
+
"patient_data": {"name": "roberto"},
|
| 12 |
+
"unique_id": "12344444",
|
| 13 |
+
"user_id": "32144444",
|
| 14 |
+
"message": {"text": text},
|
| 15 |
+
"step": "chat"
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
# Encabezados (puedes agregar autorización si es necesario)
|
| 19 |
+
headers = {
|
| 20 |
+
"Content-Type": "application/json"
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
# Enviar la solicitud POST
|
| 24 |
+
response = requests.post(url, json=data, headers=headers)
|
| 25 |
+
|
| 26 |
+
# Mostrar respuesta
|
| 27 |
+
print("Status code:", response.status_code)
|
| 28 |
+
print("Response JSON:", response.json()['output']['response'])
|
| 29 |
+
output = response.json()['output']['response']
|
| 30 |
+
return output
|
| 31 |
+
|
| 32 |
+
def interact_with_chatbot(text, conversation):
|
| 33 |
+
# Procesar el mensaje a través del modelo
|
| 34 |
+
response = model(text, conversation)
|
| 35 |
+
|
| 36 |
+
# Devolver la respuesta generada y el estado de la conversación (como lista)
|
| 37 |
+
#conversation.append((text, response)) # Agregar interacción a la lista
|
| 38 |
+
return response
|
| 39 |
+
|
| 40 |
+
# Lanzar la interfaz Gradio con ChatInterface
|
| 41 |
+
|
| 42 |
+
gr.ChatInterface(fn=interact_with_chatbot, title="👨⚕️ PreDoc Chatbot 📋💊").launch(debug=True)
|