Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ import os
|
|
4 |
import google.generativeai as genai
|
5 |
import random
|
6 |
import datetime
|
7 |
-
import base64
|
8 |
from streamlit import session_state as state
|
9 |
from formulas.webinar_formulas import webinar_formulas
|
10 |
from formulas.webinar_name_formulas import webinar_name_formulas
|
@@ -19,58 +18,37 @@ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
|
19 |
# Función auxiliar para mostrar el contenido generado y los botones de descarga
|
20 |
# In the display_generated_content function, modify the names section:
|
21 |
|
22 |
-
# Modificar la función display_generated_content para usar session_state
|
23 |
-
# Inicializar variables de estado si no existen
|
24 |
-
if 'last_generated_script' not in st.session_state:
|
25 |
-
st.session_state.last_generated_script = None
|
26 |
-
if 'last_generated_names' not in st.session_state:
|
27 |
-
st.session_state.last_generated_names = None
|
28 |
-
|
29 |
-
# Modify the display_generated_content function
|
30 |
def display_generated_content(col, generated_content, content_type):
|
31 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
32 |
|
33 |
-
#
|
34 |
if content_type == "script":
|
35 |
-
st.session_state.last_generated_script = generated_content
|
36 |
download_label = "DESCARGAR GUIÓN DE WEBINAR ▶▶"
|
37 |
file_name = f"guion_webinar_{timestamp}.txt"
|
38 |
subheader_text = "Tu guión de webinar:"
|
39 |
|
40 |
-
#
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
cursor: pointer; border-radius: 4px; font-weight: bold;">
|
49 |
-
{download_label}
|
50 |
-
</a>
|
51 |
-
"""
|
52 |
-
|
53 |
-
# Crear botón de descarga inferior con HTML mejorado
|
54 |
-
bottom_button_html = f"""
|
55 |
-
<a href="data:text/plain;base64,{b64}" download="{file_name}"
|
56 |
-
style="display: inline-block; padding: 0.5em 1em; color: white; background-color: #4CAF50;
|
57 |
-
text-align: center; text-decoration: none; font-size: 16px; margin: 4px 2px;
|
58 |
-
cursor: pointer; border-radius: 4px; font-weight: bold;">
|
59 |
-
{download_label}
|
60 |
-
</a>
|
61 |
-
"""
|
62 |
-
|
63 |
-
# Mostrar botón de descarga superior
|
64 |
-
col.markdown(top_button_html, unsafe_allow_html=True)
|
65 |
|
66 |
# Mostrar el contenido generado
|
67 |
col.subheader(subheader_text)
|
68 |
col.markdown(generated_content)
|
69 |
|
70 |
# Mostrar botón de descarga inferior
|
71 |
-
col.
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
else: # nombres
|
73 |
-
st.session_state.last_generated_names = generated_content
|
74 |
subheader_text = "Tus nombres de webinar:"
|
75 |
file_name = f"nombres_webinar_{timestamp}.txt"
|
76 |
download_label = "DESCARGAR NOMBRES DE WEBINAR ▶▶"
|
@@ -78,27 +56,28 @@ def display_generated_content(col, generated_content, content_type):
|
|
78 |
# Contar el número de nombres generados
|
79 |
num_names = len([line for line in generated_content.split('\n') if line.strip().startswith(('1.', '2.', '3.', '4.', '5.', '6.', '7.', '8.', '9.', '10.', '11.', '12.', '13.', '14.', '15.'))])
|
80 |
|
|
|
|
|
|
|
81 |
# Codificar el contenido para descarga
|
82 |
b64 = base64.b64encode(generated_content.encode()).decode()
|
83 |
|
84 |
-
# Crear botón de descarga superior con
|
85 |
top_button_html = f"""
|
86 |
-
<
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
</a>
|
92 |
"""
|
93 |
|
94 |
-
# Crear botón de descarga inferior con
|
95 |
bottom_button_html = f"""
|
96 |
-
<
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
</a>
|
102 |
"""
|
103 |
|
104 |
# Mostrar botón de descarga superior
|
@@ -116,30 +95,18 @@ def generate_and_display(col, generator_func, audience, product, temperature, se
|
|
116 |
if validate_inputs(audience, product):
|
117 |
try:
|
118 |
with col:
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
125 |
|
126 |
-
#
|
127 |
-
|
128 |
-
with st.spinner(f"Generando {'guión' if content_type == 'script' else 'nombres'} de webinar...", show_time=True):
|
129 |
-
# Llamar a la función generadora con los parámetros adecuados
|
130 |
-
generated_content = generator_func(
|
131 |
-
audience=audience,
|
132 |
-
topic=product,
|
133 |
-
temperature=temperature,
|
134 |
-
selected_formula=selected_formula,
|
135 |
-
**kwargs
|
136 |
-
)
|
137 |
-
|
138 |
-
# Mostrar el contenido generado usando la función auxiliar
|
139 |
-
display_generated_content(col, generated_content, content_type)
|
140 |
-
else:
|
141 |
-
# Mostrar el contenido existente
|
142 |
-
display_generated_content(col, existing_content, content_type)
|
143 |
|
144 |
except ValueError as e:
|
145 |
col.error(f"Error: {str(e)}")
|
|
|
4 |
import google.generativeai as genai
|
5 |
import random
|
6 |
import datetime
|
|
|
7 |
from streamlit import session_state as state
|
8 |
from formulas.webinar_formulas import webinar_formulas
|
9 |
from formulas.webinar_name_formulas import webinar_name_formulas
|
|
|
18 |
# Función auxiliar para mostrar el contenido generado y los botones de descarga
|
19 |
# In the display_generated_content function, modify the names section:
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
def display_generated_content(col, generated_content, content_type):
|
22 |
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
23 |
|
24 |
+
# Determinar el tipo de contenido para personalizar los botones y títulos
|
25 |
if content_type == "script":
|
|
|
26 |
download_label = "DESCARGAR GUIÓN DE WEBINAR ▶▶"
|
27 |
file_name = f"guion_webinar_{timestamp}.txt"
|
28 |
subheader_text = "Tu guión de webinar:"
|
29 |
|
30 |
+
# Mostrar botón de descarga superior para guiones
|
31 |
+
col.download_button(
|
32 |
+
label=download_label,
|
33 |
+
data=generated_content,
|
34 |
+
file_name=file_name,
|
35 |
+
mime="text/plain",
|
36 |
+
key=f"download_top_{content_type}"
|
37 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# Mostrar el contenido generado
|
40 |
col.subheader(subheader_text)
|
41 |
col.markdown(generated_content)
|
42 |
|
43 |
# Mostrar botón de descarga inferior
|
44 |
+
col.download_button(
|
45 |
+
label=download_label,
|
46 |
+
data=generated_content,
|
47 |
+
file_name=file_name,
|
48 |
+
mime="text/plain",
|
49 |
+
key=f"download_bottom_{content_type}"
|
50 |
+
)
|
51 |
else: # nombres
|
|
|
52 |
subheader_text = "Tus nombres de webinar:"
|
53 |
file_name = f"nombres_webinar_{timestamp}.txt"
|
54 |
download_label = "DESCARGAR NOMBRES DE WEBINAR ▶▶"
|
|
|
56 |
# Contar el número de nombres generados
|
57 |
num_names = len([line for line in generated_content.split('\n') if line.strip().startswith(('1.', '2.', '3.', '4.', '5.', '6.', '7.', '8.', '9.', '10.', '11.', '12.', '13.', '14.', '15.'))])
|
58 |
|
59 |
+
# Para los nombres, usar HTML personalizado en lugar de st.download_button
|
60 |
+
import base64
|
61 |
+
|
62 |
# Codificar el contenido para descarga
|
63 |
b64 = base64.b64encode(generated_content.encode()).decode()
|
64 |
|
65 |
+
# Crear botón de descarga superior con clase específica
|
66 |
top_button_html = f"""
|
67 |
+
<div class="custom-download-button names-download-button top-button">
|
68 |
+
<a href="data:text/plain;base64,{b64}" download="{file_name}">
|
69 |
+
{download_label}
|
70 |
+
</a>
|
71 |
+
</div>
|
|
|
72 |
"""
|
73 |
|
74 |
+
# Crear botón de descarga inferior con clase específica
|
75 |
bottom_button_html = f"""
|
76 |
+
<div class="custom-download-button names-download-button bottom-button">
|
77 |
+
<a href="data:text/plain;base64,{b64}" download="{file_name}">
|
78 |
+
{download_label}
|
79 |
+
</a>
|
80 |
+
</div>
|
|
|
81 |
"""
|
82 |
|
83 |
# Mostrar botón de descarga superior
|
|
|
95 |
if validate_inputs(audience, product):
|
96 |
try:
|
97 |
with col:
|
98 |
+
with st.spinner(f"Generando {'guión' if content_type == 'script' else 'nombres'} de webinar...", show_time=True):
|
99 |
+
# Llamar a la función generadora con los parámetros adecuados
|
100 |
+
generated_content = generator_func(
|
101 |
+
audience=audience,
|
102 |
+
topic=product,
|
103 |
+
temperature=temperature,
|
104 |
+
selected_formula=selected_formula,
|
105 |
+
**kwargs
|
106 |
+
)
|
107 |
|
108 |
+
# Mostrar el contenido generado usando la función auxiliar
|
109 |
+
display_generated_content(col, generated_content, content_type)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
except ValueError as e:
|
112 |
col.error(f"Error: {str(e)}")
|