jcmachicao
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,71 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import json
|
4 |
import os
|
5 |
from openai import OpenAI
|
@@ -58,4 +124,5 @@ interface = gr.Interface(
|
|
58 |
description="Ingrese el texto para analizar y extraer informaci贸n en un formato JSON predefinido."
|
59 |
)
|
60 |
|
61 |
-
interface.launch()
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import os
|
4 |
+
|
5 |
+
# Set the OpenAI API key
|
6 |
+
openai.api_key = os.getenv("OPENAI_KEY") # Ensure this is set in the environment
|
7 |
+
|
8 |
+
# Define the LLM function
|
9 |
+
def generacion_llm(texto_input):
|
10 |
+
# Define the system and user messages
|
11 |
+
formato_json = '''
|
12 |
+
{
|
13 |
+
"reto": " ",
|
14 |
+
"dudas": " ",
|
15 |
+
"preguntas": " ",
|
16 |
+
"expectativas": " "
|
17 |
+
}
|
18 |
+
'''
|
19 |
+
|
20 |
+
mensaje_sistema = (
|
21 |
+
"Eres un experto en identificar aspectos descriptivos de las razones "
|
22 |
+
"por las cuales un usuario necesita asesor铆a para implementar retos "
|
23 |
+
"que involucren inteligencia artificial de varios tipos."
|
24 |
+
)
|
25 |
+
|
26 |
+
mensaje_usuario = (
|
27 |
+
f"Analizar el texto mostrado al final, buscando identificar los siguientes "
|
28 |
+
f"extractos en el formato JSON: {formato_json}\n\nTexto a Analizar: {texto_input}"
|
29 |
+
)
|
30 |
+
|
31 |
+
# Call OpenAI API
|
32 |
+
try:
|
33 |
+
response = openai.ChatCompletion.create(
|
34 |
+
model="gpt-3.5-turbo",
|
35 |
+
messages=[
|
36 |
+
{"role": "system", "content": mensaje_sistema},
|
37 |
+
{"role": "user", "content": mensaje_usuario}
|
38 |
+
],
|
39 |
+
temperature=0.8,
|
40 |
+
max_tokens=300,
|
41 |
+
top_p=1,
|
42 |
+
frequency_penalty=0,
|
43 |
+
presence_penalty=0
|
44 |
+
)
|
45 |
+
|
46 |
+
# Extract the generated text from the response
|
47 |
+
texto_respuesta = response["choices"][0]["message"]["content"]
|
48 |
+
|
49 |
+
# Try parsing as JSON (if applicable)
|
50 |
+
return texto_respuesta # Return plain text for now (replace with JSON if needed)
|
51 |
+
except Exception as e:
|
52 |
+
return f"Error: {e}"
|
53 |
+
|
54 |
+
# Define Gradio app
|
55 |
+
interface = gr.Interface(
|
56 |
+
fn=generacion_llm,
|
57 |
+
inputs=gr.Textbox(label="Ingrese su texto para analizar"),
|
58 |
+
outputs=gr.Textbox(label="Resultado JSON"),
|
59 |
+
title="Extractor de Texto a JSON",
|
60 |
+
description="Ingrese el texto para analizar y extraer informaci贸n en un formato JSON predefinido."
|
61 |
+
)
|
62 |
+
|
63 |
+
interface.launch()
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
'''
|
68 |
+
import gradio as gr
|
69 |
import json
|
70 |
import os
|
71 |
from openai import OpenAI
|
|
|
124 |
description="Ingrese el texto para analizar y extraer informaci贸n en un formato JSON predefinido."
|
125 |
)
|
126 |
|
127 |
+
interface.launch()
|
128 |
+
'''
|