Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from gtts import gTTS
|
|
5 |
import os
|
6 |
|
7 |
# Configuración de la página de Streamlit
|
8 |
-
st.set_page_config(page_title="✨ Soph-IA: Tu Asistente Inteligente", layout="
|
9 |
|
10 |
# Obtener la API key desde los secretos de Hugging Face
|
11 |
api_key = st.secrets["API_KEY"]
|
@@ -42,43 +42,79 @@ def hablar_texto(texto):
|
|
42 |
except Exception as e:
|
43 |
st.error(f"Error al generar el audio: {e}")
|
44 |
|
45 |
-
#
|
46 |
-
st.
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
# Espacio dinámico para respuestas
|
55 |
espacio_contenido_generado = st.empty()
|
56 |
|
57 |
-
# Elegir tipo de entrada: pregunta o imagen
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
if
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
# Mensaje de cierre amigable
|
83 |
-
st.
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
5 |
import os
|
6 |
|
7 |
# Configuración de la página de Streamlit
|
8 |
+
st.set_page_config(page_title="✨ Soph-IA: Tu Asistente Inteligente", layout="centered", page_icon="🤖")
|
9 |
|
10 |
# Obtener la API key desde los secretos de Hugging Face
|
11 |
api_key = st.secrets["API_KEY"]
|
|
|
42 |
except Exception as e:
|
43 |
st.error(f"Error al generar el audio: {e}")
|
44 |
|
45 |
+
# CSS adicional para centrar el contenido
|
46 |
+
st.markdown("""
|
47 |
+
<style>
|
48 |
+
.centered-content {
|
49 |
+
display: flex;
|
50 |
+
justify-content: center;
|
51 |
+
align-items: center;
|
52 |
+
flex-direction: column;
|
53 |
+
text-align: center;
|
54 |
+
}
|
55 |
+
.title-style {
|
56 |
+
font-size: 3em;
|
57 |
+
font-weight: bold;
|
58 |
+
margin-bottom: 20px;
|
59 |
+
}
|
60 |
+
.subtitle-style {
|
61 |
+
font-size: 1.5em;
|
62 |
+
margin-bottom: 40px;
|
63 |
+
color: #4CAF50;
|
64 |
+
}
|
65 |
+
.input-box {
|
66 |
+
width: 50%;
|
67 |
+
margin: 0 auto;
|
68 |
+
}
|
69 |
+
</style>
|
70 |
+
""", unsafe_allow_html=True)
|
71 |
+
|
72 |
+
# Contenido principal centrado
|
73 |
+
st.markdown('<div class="centered-content">', unsafe_allow_html=True)
|
74 |
+
|
75 |
+
st.markdown('<div class="title-style">✨ ¡Bienvenido a Soph-IA! 💡</div>', unsafe_allow_html=True)
|
76 |
+
|
77 |
+
# Introducción amigable con emojis y centrado
|
78 |
+
st.markdown("""
|
79 |
+
<div class="subtitle-style">
|
80 |
+
Soy **Soph-IA**, tu asistente virtual inteligente 🤖. Estoy aquí para ayudarte a responder preguntas y analizar imágenes.
|
81 |
+
¡No dudes en preguntar lo que necesites! 😊
|
82 |
+
</div>
|
83 |
+
""", unsafe_allow_html=True)
|
84 |
|
85 |
# Espacio dinámico para respuestas
|
86 |
espacio_contenido_generado = st.empty()
|
87 |
|
88 |
+
# Elegir tipo de entrada: pregunta o imagen (centrado)
|
89 |
+
st.markdown('<div class="input-box">', unsafe_allow_html=True)
|
90 |
+
|
91 |
+
tipo_entrada = st.selectbox("Selecciona lo que quieres hacer:", ["❓ Hacer una pregunta", "🖼️ Subir una imagen"])
|
92 |
+
|
93 |
+
if tipo_entrada == "❓ Hacer una pregunta":
|
94 |
+
entrada_texto = st.text_input("Escribe tu pregunta aquí:")
|
95 |
+
if entrada_texto:
|
96 |
+
with st.spinner("✨ Generando respuesta..."):
|
97 |
+
resultado = procesar_texto(entrada_texto)
|
98 |
+
espacio_contenido_generado.write(f"**Respuesta:** {resultado}")
|
99 |
+
if st.button("🔊 Escuchar respuesta"):
|
100 |
+
hablar_texto(resultado)
|
101 |
+
|
102 |
+
elif tipo_entrada == "🖼️ Subir una imagen":
|
103 |
+
entrada_imagen = st.file_uploader("Sube tu imagen aquí", type=["jpg", "png", "jpeg"])
|
104 |
+
if entrada_imagen:
|
105 |
+
imagen = Image.open(entrada_imagen)
|
106 |
+
st.image(imagen, caption='✨ Imagen cargada con éxito', use_column_width=True)
|
107 |
+
with st.spinner("✨ Analizando imagen..."):
|
108 |
+
respuesta = procesar_imagen(imagen)
|
109 |
+
espacio_contenido_generado.write(f"**Resultado del análisis de la imagen:** {respuesta}")
|
110 |
+
|
111 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
112 |
+
|
113 |
+
# Mensaje de cierre amigable y centrado
|
114 |
+
st.markdown("""
|
115 |
+
<div class="subtitle-style">
|
116 |
+
🌟 ¡Gracias por usar **Soph-IA**! Estoy aquí para ti en cualquier momento. 😊
|
117 |
+
</div>
|
118 |
+
""", unsafe_allow_html=True)
|
119 |
+
|
120 |
+
st.markdown('</div>', unsafe_allow_html=True)
|