Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
-
import
|
2 |
import google.generativeai as genai
|
3 |
import os
|
4 |
from dotenv import load_dotenv
|
|
|
5 |
import textwrap
|
6 |
|
7 |
# Cargar variables de entorno
|
@@ -11,7 +12,7 @@ load_dotenv()
|
|
11 |
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
12 |
|
13 |
def to_markdown(text):
|
14 |
-
return textwrap.indent(text, '> ', predicate=lambda _: True)
|
15 |
|
16 |
def generate_opening_paragraph(target_audience, product, temperature, text_type, model_name):
|
17 |
# Crear la configuración del modelo
|
@@ -71,34 +72,42 @@ def generate_opening_paragraph(target_audience, product, temperature, text_type,
|
|
71 |
response = chat_session.send_message("Genera el párrafo de apertura")
|
72 |
return to_markdown(response.text)
|
73 |
|
74 |
-
#
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
#
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
st.markdown(output_text)
|
91 |
-
|
92 |
-
with col2:
|
93 |
-
if st.button("Empezar de nuevo"):
|
94 |
-
# Limpiar campos de entrada
|
95 |
-
target_audience = ""
|
96 |
-
product = ""
|
97 |
-
temperature = 0.5
|
98 |
-
text_type = "Página de Ventas"
|
99 |
-
model_selector = "gemini-1.5-flash"
|
100 |
|
101 |
-
#
|
102 |
-
|
103 |
-
st.markdown("**Párrafo de Apertura Generado:**")
|
104 |
-
st.markdown(output_text)
|
|
|
1 |
+
import gradio as gr
|
2 |
import google.generativeai as genai
|
3 |
import os
|
4 |
from dotenv import load_dotenv
|
5 |
+
from gradio import Markdown
|
6 |
import textwrap
|
7 |
|
8 |
# Cargar variables de entorno
|
|
|
12 |
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
13 |
|
14 |
def to_markdown(text):
|
15 |
+
return Markdown(textwrap.indent(text, '> ', predicate=lambda _: True))
|
16 |
|
17 |
def generate_opening_paragraph(target_audience, product, temperature, text_type, model_name):
|
18 |
# Crear la configuración del modelo
|
|
|
72 |
response = chat_session.send_message("Genera el párrafo de apertura")
|
73 |
return to_markdown(response.text)
|
74 |
|
75 |
+
# Configurar la interfaz de usuario con Gradio
|
76 |
+
css = """
|
77 |
+
<style>
|
78 |
+
body { font-family: Arial, sans-serif; }
|
79 |
+
.gradio-container { max-width: 800px; margin: auto; }
|
80 |
+
</style>
|
81 |
+
"""
|
82 |
|
83 |
+
with gr.Blocks(css=css) as iface:
|
84 |
+
gr.HTML("<h1 class='text-3xl font-bold text-center mb-6'>Generador de Párrafos de Apertura</h1>")
|
85 |
+
|
86 |
+
with gr.Row():
|
87 |
+
with gr.Column():
|
88 |
+
target_audience = gr.Textbox(label="Público Objetivo", placeholder="Ejemplo: Estudiantes Universitarios")
|
89 |
+
product = gr.Textbox(label="Producto", placeholder="Ejemplo: Curso de Inglés")
|
90 |
+
temperature = gr.Slider(minimum=0, maximum=1, value=0.5, step=0.1, label="Creatividad")
|
91 |
+
text_type = gr.Dropdown(choices=["Página de Ventas", "Correo", "Historia"], label="Tipo de Texto", value="Página de Ventas")
|
92 |
+
model_selector = gr.Dropdown(choices=["gemini-1.5-flash", "gemini-1.5-pro"], value="gemini-1.5-flash", label="Selecciona el modelo")
|
93 |
+
|
94 |
+
# Colocar los botones en una misma fila
|
95 |
+
with gr.Row():
|
96 |
+
submit_btn = gr.Button("Generar Párrafo de Apertura", variant="primary")
|
97 |
+
clear_btn = gr.Button("Empezar de nuevo", variant="secondary")
|
98 |
+
|
99 |
+
with gr.Column():
|
100 |
+
output_text = gr.Markdown(label="Párrafo de Apertura Generado")
|
101 |
+
|
102 |
+
# Funcionalidad del botón Generar
|
103 |
+
submit_btn.click(fn=generate_opening_paragraph, inputs=[target_audience, product, temperature, text_type, model_selector], outputs=output_text)
|
104 |
|
105 |
+
# Funcionalidad del botón Limpiar: restablecer valores a los predeterminados
|
106 |
+
clear_btn.click(
|
107 |
+
fn=lambda: ("", "", 0.5, "Página de Ventas", "gemini-1.5-flash"),
|
108 |
+
inputs=[],
|
109 |
+
outputs=[target_audience, product, temperature, text_type, model_selector]
|
110 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
+
# Lanzar la interfaz
|
113 |
+
iface.launch()
|
|
|
|