|
import gradio as gr |
|
import openai |
|
import os |
|
import openai |
|
from openai import OpenAI |
|
api_key = os.getenv("OPENAI_KEY") |
|
client = OpenAI(api_key=api_key) |
|
|
|
|
|
def generacion_llm(texto_input): |
|
|
|
formato_json = ''' |
|
{ |
|
"reto": " ", |
|
"dudas": " ", |
|
"preguntas": " ", |
|
"expectativas": " " |
|
} |
|
''' |
|
|
|
mensaje_sistema = ( |
|
"Eres un experto en identificar aspectos descriptivos de las razones " |
|
"por las cuales un usuario necesita asesor铆a para implementar retos " |
|
"que involucren inteligencia artificial de varios tipos." |
|
) |
|
|
|
mensaje_usuario = ( |
|
f"Analizar el texto mostrado al final, buscando identificar los siguientes " |
|
f"extractos en el formato JSON: {formato_json}\n\nTexto a Analizar: {texto_input}" |
|
) |
|
|
|
version_model = 'gpt-3.5-turbo-0125' |
|
|
|
|
|
try: |
|
response = client.chat.completions.create( |
|
model=version_model, |
|
messages=[ |
|
{"role": "system", "content": mensaje_sistema}, |
|
{"role": "user", "content": mensaje_usuario} |
|
], |
|
temperature=0.8, |
|
max_tokens=300, |
|
top_p=1, |
|
|
|
) |
|
|
|
|
|
texto_respuesta = response.choices[0].message.content |
|
|
|
|
|
return texto_respuesta |
|
except Exception as e: |
|
return f"Error: {e}" |
|
|
|
|
|
with gr.Blocks() as interface: |
|
|
|
gr.Markdown( |
|
""" |
|
# Estructurador de Autodiagn贸stico |
|
Ingrese el texto para analizar y extraer informaci贸n en un formato JSON predefinido. |
|
""" |
|
) |
|
|
|
input_text = gr.Textbox(label="Ingrese su texto libre para estructurar.") |
|
output_json = gr.Textbox(label="Resultado JSON") |
|
submit_button = gr.Button("Procesar") |
|
|
|
|
|
submit_button.click(fn=generacion_llm, inputs=input_text, outputs=output_json) |
|
|
|
|
|
gr.Markdown( |
|
""" |
|
<br> |
|
<div style="text-align: center;"> |
|
<img src="gdmk logo.png" alt="Logo" style="width: 200px;"> |
|
</div> |
|
""" |
|
) |
|
|
|
|
|
interface.launch(share=True) |
|
|