qwerty
Browse files- app.py +99 -0
- requirements.txt +69 -0
app.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import time
|
| 4 |
+
from openai import OpenAI
|
| 5 |
+
import os
|
| 6 |
+
from dotenv import load_dotenv
|
| 7 |
+
|
| 8 |
+
# Cargar las variables de entorno y configurar el cliente de OpenAI
|
| 9 |
+
load_dotenv()
|
| 10 |
+
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 11 |
+
my_assistant = client.beta.assistants.retrieve("asst_m1mvLz5rtxcROa4DWYWcuRDr")
|
| 12 |
+
def submit_message(assistant_id, thread, user_message):
|
| 13 |
+
client.beta.threads.messages.create(
|
| 14 |
+
thread_id=thread.id, role="user", content=user_message
|
| 15 |
+
)
|
| 16 |
+
return client.beta.threads.runs.create(
|
| 17 |
+
thread_id=thread.id,
|
| 18 |
+
assistant_id=assistant_id,
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def get_response(thread):
|
| 24 |
+
return client.beta.threads.messages.list(thread_id=thread.id, order="asc")
|
| 25 |
+
|
| 26 |
+
def submit_to_openai(nombre,demografia, ingresos, situacion_laboral, intereses, accesibilidad_tecnologia, complejidad):
|
| 27 |
+
send_message = f"""Nombre del Curso: {nombre}
|
| 28 |
+
Demograf铆a Local: {demografia}
|
| 29 |
+
Nivel de Ingresos: {ingresos}
|
| 30 |
+
Situaci贸n Laboral: {situacion_laboral}
|
| 31 |
+
Intereses Espec铆ficos de la Poblaci贸n: {intereses}
|
| 32 |
+
Accesibilidad a la Tecnolog铆a: {accesibilidad_tecnologia}
|
| 33 |
+
Complejidad del Curso: {complejidad}"""
|
| 34 |
+
|
| 35 |
+
empty_thread = client.beta.threads.create()
|
| 36 |
+
submit_message(my_assistant.id, empty_thread, send_message)
|
| 37 |
+
time.sleep(19) # Esperar a que la respuesta est茅 disponible
|
| 38 |
+
response = get_response(empty_thread)
|
| 39 |
+
return response
|
| 40 |
+
|
| 41 |
+
def curso_info(nombre, demografia, ingresos, situacion_laboral, intereses, accesibilidad_tecnologia, complejidad):
|
| 42 |
+
# Suponiendo que submit_to_openai ya est谩 definido y env铆a correctamente los par谩metros
|
| 43 |
+
respuesta_api = submit_to_openai(nombre, demografia, ingresos, situacion_laboral, intereses, accesibilidad_tecnologia, complejidad)
|
| 44 |
+
|
| 45 |
+
# Extraer el contenido del segundo mensaje (铆ndice 1) en la lista de respuestas
|
| 46 |
+
# Asumiendo que el segundo mensaje contiene la respuesta en formato markdown (```json ...)
|
| 47 |
+
contenido_respuesta = respuesta_api.data[1].content[0].text.value
|
| 48 |
+
# Procesar el contenido para extraer el JSON
|
| 49 |
+
# Eliminar los backticks triples y cualquier otro formato markdown si es necesario
|
| 50 |
+
json_str = contenido_respuesta.strip("`")
|
| 51 |
+
|
| 52 |
+
# Parsear el string JSON extra铆do
|
| 53 |
+
respuesta_json = json.loads(json_str)
|
| 54 |
+
nombre_curso = respuesta_json["nombrecurso"]
|
| 55 |
+
calificacion = respuesta_json["calificacionfinal"]
|
| 56 |
+
|
| 57 |
+
# A帽adir emojis y descripciones seg煤n la calificaci贸n
|
| 58 |
+
if calificacion >= 4.5:
|
| 59 |
+
emoji = "馃専馃専馃専馃専馃専"
|
| 60 |
+
descripcion = "隆Excelente! Un curso altamente recomendado."
|
| 61 |
+
elif calificacion >= 3.5:
|
| 62 |
+
emoji = "馃専馃専馃専馃専"
|
| 63 |
+
descripcion = "Muy bueno. Vale la pena considerarlo."
|
| 64 |
+
elif calificacion >= 2.5:
|
| 65 |
+
emoji = "馃専馃専馃専"
|
| 66 |
+
descripcion = "Bueno, pero hay margen de mejora."
|
| 67 |
+
elif calificacion >= 1.5:
|
| 68 |
+
emoji = "馃専馃専"
|
| 69 |
+
descripcion = "Regular. Podr铆a ser mejor."
|
| 70 |
+
else:
|
| 71 |
+
emoji = "馃専"
|
| 72 |
+
descripcion = "Por debajo de las expectativas."
|
| 73 |
+
|
| 74 |
+
# Combinar todo en un mensaje personalizado
|
| 75 |
+
mensaje = f"Curso: {nombre_curso}\nCalificaci贸n: {calificacion} {emoji}\n{descripcion}"
|
| 76 |
+
|
| 77 |
+
return mensaje
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 81 |
+
gr.Interface(
|
| 82 |
+
fn=curso_info,
|
| 83 |
+
inputs=[
|
| 84 |
+
gr.Textbox(label="Nombre del Curso", type="text"),
|
| 85 |
+
gr.Slider(minimum=1, maximum=5, label="Demograf铆a Local"),
|
| 86 |
+
gr.Slider(minimum=1, maximum=5, label="Nivel de Ingresos"),
|
| 87 |
+
gr.Slider(minimum=1, maximum=5, label="Situaci贸n Laboral"),
|
| 88 |
+
gr.Slider(minimum=1, maximum=5, label="Intereses Espec铆ficos de la Poblaci贸n"),
|
| 89 |
+
gr.Slider(minimum=1, maximum=5, label="Accesibilidad a la Tecnolog铆a"),
|
| 90 |
+
gr.Slider(minimum=1, maximum=5, label="Complejidad del Curso")
|
| 91 |
+
],
|
| 92 |
+
outputs="text",
|
| 93 |
+
title="Informaci贸n del Curso",
|
| 94 |
+
description="Ajusta los deslizadores para definir los par谩metros del curso y recibir recomendaciones."
|
| 95 |
+
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
if __name__ == "__main__":
|
| 99 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
aiofiles==23.2.1
|
| 2 |
+
altair==5.2.0
|
| 3 |
+
annotated-types==0.6.0
|
| 4 |
+
anyio==4.3.0
|
| 5 |
+
attrs==23.2.0
|
| 6 |
+
certifi==2024.2.2
|
| 7 |
+
charset-normalizer==3.3.2
|
| 8 |
+
click==8.1.7
|
| 9 |
+
colorama==0.4.6
|
| 10 |
+
contourpy==1.2.0
|
| 11 |
+
cycler==0.12.1
|
| 12 |
+
distro==1.9.0
|
| 13 |
+
fastapi==0.110.0
|
| 14 |
+
ffmpy==0.3.2
|
| 15 |
+
filelock==3.13.1
|
| 16 |
+
fonttools==4.49.0
|
| 17 |
+
fsspec==2024.2.0
|
| 18 |
+
gradio==4.19.2
|
| 19 |
+
gradio_client==0.10.1
|
| 20 |
+
h11==0.14.0
|
| 21 |
+
httpcore==1.0.4
|
| 22 |
+
httpx==0.27.0
|
| 23 |
+
huggingface-hub==0.20.3
|
| 24 |
+
idna==3.6
|
| 25 |
+
importlib_resources==6.1.2
|
| 26 |
+
Jinja2==3.1.3
|
| 27 |
+
jsonschema==4.21.1
|
| 28 |
+
jsonschema-specifications==2023.12.1
|
| 29 |
+
kiwisolver==1.4.5
|
| 30 |
+
load-dotenv==0.1.0
|
| 31 |
+
markdown-it-py==3.0.0
|
| 32 |
+
MarkupSafe==2.1.5
|
| 33 |
+
matplotlib==3.8.3
|
| 34 |
+
mdurl==0.1.2
|
| 35 |
+
numpy==1.26.4
|
| 36 |
+
openai==1.12.0
|
| 37 |
+
orjson==3.9.15
|
| 38 |
+
packaging==23.2
|
| 39 |
+
pandas==2.2.1
|
| 40 |
+
pillow==10.2.0
|
| 41 |
+
pydantic==2.6.2
|
| 42 |
+
pydantic_core==2.16.3
|
| 43 |
+
pydub==0.25.1
|
| 44 |
+
Pygments==2.17.2
|
| 45 |
+
pyparsing==3.1.1
|
| 46 |
+
python-dateutil==2.8.2
|
| 47 |
+
python-dotenv==1.0.1
|
| 48 |
+
python-multipart==0.0.9
|
| 49 |
+
pytz==2024.1
|
| 50 |
+
PyYAML==6.0.1
|
| 51 |
+
referencing==0.33.0
|
| 52 |
+
requests==2.31.0
|
| 53 |
+
rich==13.7.0
|
| 54 |
+
rpds-py==0.18.0
|
| 55 |
+
ruff==0.2.2
|
| 56 |
+
semantic-version==2.10.0
|
| 57 |
+
shellingham==1.5.4
|
| 58 |
+
six==1.16.0
|
| 59 |
+
sniffio==1.3.1
|
| 60 |
+
starlette==0.36.3
|
| 61 |
+
tomlkit==0.12.0
|
| 62 |
+
toolz==0.12.1
|
| 63 |
+
tqdm==4.66.2
|
| 64 |
+
typer==0.9.0
|
| 65 |
+
typing_extensions==4.10.0
|
| 66 |
+
tzdata==2024.1
|
| 67 |
+
urllib3==2.2.1
|
| 68 |
+
uvicorn==0.27.1
|
| 69 |
+
websockets==11.0.3
|