Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
-
import
|
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,7 +11,7 @@ load_dotenv()
|
|
12 |
genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
|
13 |
|
14 |
def to_markdown(text):
|
15 |
-
return
|
16 |
|
17 |
def generate_opening_paragraph(target_audience, product, temperature, text_type, model_name):
|
18 |
# Crear la configuración del modelo
|
@@ -72,42 +71,34 @@ def generate_opening_paragraph(target_audience, product, temperature, text_type,
|
|
72 |
response = chat_session.send_message("Genera el párrafo de apertura")
|
73 |
return to_markdown(response.text)
|
74 |
|
75 |
-
#
|
76 |
-
|
77 |
-
<style>
|
78 |
-
body { font-family: Arial, sans-serif; }
|
79 |
-
.gradio-container { max-width: 800px; margin: auto; }
|
80 |
-
</style>
|
81 |
-
"""
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
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 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
|
112 |
-
#
|
113 |
-
|
|
|
|
|
|
1 |
+
import streamlit as st
|
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 |
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 |
response = chat_session.send_message("Genera el párrafo de apertura")
|
72 |
return to_markdown(response.text)
|
73 |
|
74 |
+
# Configuración de la interfaz de Streamlit
|
75 |
+
st.title("Generador de Párrafos de Apertura")
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
+
# Entradas
|
78 |
+
target_audience = st.text_input("Público Objetivo", "Ejemplo: Estudiantes Universitarios")
|
79 |
+
product = st.text_input("Producto", "Ejemplo: Curso de Inglés")
|
80 |
+
temperature = st.slider("Creatividad", 0.0, 1.0, 0.5, 0.1)
|
81 |
+
text_type = st.selectbox("Tipo de Texto", ["Página de Ventas", "Correo", "Historia"])
|
82 |
+
model_selector = st.selectbox("Selecciona el modelo", ["gemini-1.5-flash", "gemini-1.5-pro"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
|
84 |
+
# Botones
|
85 |
+
col1, col2 = st.columns(2)
|
86 |
+
|
87 |
+
with col1:
|
88 |
+
if st.button("Generar Párrafo de Apertura"):
|
89 |
+
output_text = generate_opening_paragraph(target_audience, product, temperature, text_type, model_selector)
|
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 |
+
# Mostrar resultado (si se generó uno)
|
102 |
+
if 'output_text' in locals():
|
103 |
+
st.markdown("**Párrafo de Apertura Generado:**")
|
104 |
+
st.markdown(output_text)
|