Update app.py
Browse files
app.py
CHANGED
@@ -3,14 +3,18 @@ from PIL import Image
|
|
3 |
import google.generativeai as genai
|
4 |
from gtts import gTTS
|
5 |
import os
|
6 |
-
import io
|
7 |
|
8 |
# Configuración de la página de Streamlit
|
9 |
-
st.set_page_config(page_title="
|
10 |
|
11 |
# Obtener la API key desde los secretos de Hugging Face
|
12 |
-
api_key = st.secrets["API_KEY"]
|
13 |
|
|
|
|
|
|
|
|
|
|
|
14 |
def procesar_texto(texto):
|
15 |
genai.configure(api_key=api_key)
|
16 |
modelo = genai.GenerativeModel('gemini-1.5-pro-latest')
|
@@ -38,38 +42,43 @@ def hablar_texto(texto):
|
|
38 |
except Exception as e:
|
39 |
st.error(f"Error al generar el audio: {e}")
|
40 |
|
41 |
-
|
|
|
42 |
|
43 |
-
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
#
|
46 |
-
|
47 |
-
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
48 |
-
|
49 |
-
st.write("¡Hola! Soy tu asistente virtual. ¿Cómo puedo ayudarte hoy? 😊")
|
50 |
|
|
|
51 |
col1, col2 = st.columns([1, 3])
|
52 |
|
53 |
with col1:
|
54 |
-
tipo_entrada = st.selectbox("Selecciona
|
55 |
|
56 |
with col2:
|
57 |
-
if tipo_entrada == "
|
58 |
-
entrada_texto = st.text_input("
|
59 |
if entrada_texto:
|
60 |
-
with st.spinner("Generando respuesta..."):
|
61 |
resultado = procesar_texto(entrada_texto)
|
62 |
espacio_contenido_generado.write(f"**Respuesta:** {resultado}")
|
63 |
if st.button("🔊 Escuchar respuesta"):
|
64 |
hablar_texto(resultado)
|
65 |
|
66 |
-
elif tipo_entrada == "🖼️ Subir imagen":
|
67 |
-
entrada_imagen = st.file_uploader("Sube
|
68 |
if entrada_imagen:
|
69 |
imagen = Image.open(entrada_imagen)
|
70 |
-
st.image(imagen, caption='Imagen
|
71 |
-
with st.spinner("
|
72 |
respuesta = procesar_imagen(imagen)
|
73 |
-
espacio_contenido_generado.write(f"**
|
|
|
|
|
|
|
74 |
|
75 |
-
st.write("¡Gracias por usar el ChatBot! 😊")
|
|
|
3 |
import google.generativeai as genai
|
4 |
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="wide", page_icon="🤖")
|
9 |
|
10 |
# Obtener la API key desde los secretos de Hugging Face
|
11 |
+
api_key = st.secrets["API_KEY"]
|
12 |
|
13 |
+
# Cargar y aplicar CSS personalizado
|
14 |
+
with open("./style.css") as f:
|
15 |
+
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
16 |
+
|
17 |
+
# Funciones de procesamiento
|
18 |
def procesar_texto(texto):
|
19 |
genai.configure(api_key=api_key)
|
20 |
modelo = genai.GenerativeModel('gemini-1.5-pro-latest')
|
|
|
42 |
except Exception as e:
|
43 |
st.error(f"Error al generar el audio: {e}")
|
44 |
|
45 |
+
# Contenido principal
|
46 |
+
st.title("✨ ¡Bienvenido a Soph-IA! 💡")
|
47 |
|
48 |
+
# Introducción amigable con emojis
|
49 |
+
st.write("""
|
50 |
+
### 🤖 ¿Quién soy?
|
51 |
+
Soy **Soph-IA**, tu asistente virtual inteligente 🤖. Estoy aquí para ayudarte a responder preguntas y analizar imágenes. ¡No dudes en preguntar lo que necesites! 😊
|
52 |
+
""")
|
53 |
|
54 |
+
# Espacio dinámico para respuestas
|
55 |
+
espacio_contenido_generado = st.empty()
|
|
|
|
|
|
|
56 |
|
57 |
+
# Elegir tipo de entrada: pregunta o imagen
|
58 |
col1, col2 = st.columns([1, 3])
|
59 |
|
60 |
with col1:
|
61 |
+
tipo_entrada = st.selectbox("Selecciona lo que quieres hacer:", ["❓ Hacer una pregunta", "🖼️ Subir una imagen"])
|
62 |
|
63 |
with col2:
|
64 |
+
if tipo_entrada == "❓ Hacer una pregunta":
|
65 |
+
entrada_texto = st.text_input("Escribe tu pregunta aquí:")
|
66 |
if entrada_texto:
|
67 |
+
with st.spinner("✨ Generando respuesta..."):
|
68 |
resultado = procesar_texto(entrada_texto)
|
69 |
espacio_contenido_generado.write(f"**Respuesta:** {resultado}")
|
70 |
if st.button("🔊 Escuchar respuesta"):
|
71 |
hablar_texto(resultado)
|
72 |
|
73 |
+
elif tipo_entrada == "🖼️ Subir una imagen":
|
74 |
+
entrada_imagen = st.file_uploader("Sube tu imagen aquí", type=["jpg", "png", "jpeg"])
|
75 |
if entrada_imagen:
|
76 |
imagen = Image.open(entrada_imagen)
|
77 |
+
st.image(imagen, caption='✨ Imagen cargada con éxito', use_column_width=True)
|
78 |
+
with st.spinner("✨ Analizando imagen..."):
|
79 |
respuesta = procesar_imagen(imagen)
|
80 |
+
espacio_contenido_generado.write(f"**Resultado del análisis de la imagen:** {respuesta}")
|
81 |
+
|
82 |
+
# Mensaje de cierre amigable
|
83 |
+
st.write("🌟 ¡Gracias por usar **Soph-IA**! Estamos aquí para ti en cualquier momento. 😊")
|
84 |
|
|