File size: 3,188 Bytes
68103f4
6da4e96
 
d31531c
 
deb85f7
 
fe40d69
d31531c
6da4e96
 
 
 
 
 
25d7047
f7388bb
 
 
 
25d7047
6da4e96
 
 
 
 
 
 
 
 
 
25d7047
 
 
 
f7388bb
 
6da4e96
 
e0b9986
 
6da4e96
 
13b8afd
e0b9986
6da4e96
 
 
 
 
 
 
13b8afd
6da4e96
13b8afd
6da4e96
7687135
6da4e96
 
 
 
 
 
 
8de164f
 
 
8a8063f
7965ad3
 
cb53003
 
 
 
 
 
 
56c1172
7965ad3
8de164f
 
 
 
 
 
 
 
 
1a4d8c2
2b5a6ed
1a4d8c2
2154369
8de164f
 
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import gradio as gr
import openai
import os
import openai
from openai import OpenAI
from gdmk_aux import generacion_llm

api_key = os.getenv("OPENAI_KEY")
client = OpenAI(api_key=api_key)

# Define the LLM function
def generacion_llm(texto_input):
    # Define the system and user messages
    formato_json = '''
      {
        "nombre_usuario": "           ",
        "ubicaci贸n_geogr谩fica": "        ",
        "descripci贸n_reto": "            ",
        "dudas_conceptuales": "            ",
        "certezas_conceptuales": "          ",
        "expectativas_del_taller": "            "
      }
    '''
    
    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: \nTexto a Analizar: {texto_input}, que es una redacci贸n \
        libre de un usuario que busca asesor铆a para su uso 贸ptimo de la inteligencia \
        artificial, que busca orientaci贸n a trav茅s de un taller de asesor铆a de un facilitador, \
        para lo cual te pido identifiques los siguientes extractos del texto \
        en el formato JSON: {formato_json}\n Si no hubiera claridad suficiente sobre alguno \
        de los contenidos del formato JSON, escribir 'No hay suficiente informaci贸n'"
    )

    version_model = 'gpt-3.5-turbo-0125'

    # Call OpenAI API
    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,

        )

        # Extract the generated text from the response
        texto_respuesta = response.choices[0].message.content
        
        # Try parsing as JSON (if applicable)
        return texto_respuesta  # Return plain text for now (replace with JSON if needed)
    except Exception as e:
        return f"Error: {e}"

# Define Gradio app
with gr.Blocks() as interface:
    # Title and description
    gr.Markdown(
    """
    # Estructurador de Autodiagn贸stico
    Ingrese el texto para analizar y extraer informaci贸n en un formato JSON predefinido.
    
    Aseg煤rese de incluir, no necesariamente en orden:
    * Nombre de usuario.
    * Ubicaci贸n geogr谩fica (ciudad, pa铆s).
    * Descripci贸n de su reto.
    * Dudas conceptuales sobre tecnolog铆as cognitivas.
    * Certezas conceptuales.
    * Expectativas del taller.
    """
    )
    # Input and output components
    input_text = gr.Textbox(label="Ingrese su texto libre para estructurar.")
    output_json = gr.Textbox(label="Resultado JSON")
    submit_button = gr.Button("Procesar")

    # Link the input/output and function
    submit_button.click(fn=generacion_llm, inputs=input_text, outputs=output_json)

    gr.Markdown(
        """Potenciado por GestioDin谩mica漏2024"""
    )
    gr.Image('gdmk_logo.png')
# Launch the interface
interface.launch(share=True)