jeysshon commited on
Commit
721c976
·
verified ·
1 Parent(s): e286e63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -79
app.py CHANGED
@@ -3,18 +3,14 @@ from PIL import Image
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="centered", 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,79 +38,38 @@ def hablar_texto(texto):
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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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="🤖 Soph-IA", layout="wide")
10
 
11
  # Obtener la API key desde los secretos de Hugging Face
12
+ api_key = st.secrets["API_KEY"] # Accede al secreto
13
 
 
 
 
 
 
14
  def procesar_texto(texto):
15
  genai.configure(api_key=api_key)
16
  modelo = genai.GenerativeModel('gemini-1.5-pro-latest')
 
38
  except Exception as e:
39
  st.error(f"Error al generar el audio: {e}")
40
 
41
+ st.title("🤖 ¡Bienvenido a ChatBot!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  espacio_contenido_generado = st.empty()
44
 
45
+ # Cargar y aplicar CSS personalizado
46
+ with open("./style.css") as f:
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 el tipo de entrada", ["Haz una pregunta ❓", "🖼️ Subir imagen"])
55
+
56
+ with col2:
57
+ if tipo_entrada == "Haz una pregunta ❓":
58
+ entrada_texto = st.text_input("Ingresa tu pregunta aquí:")
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 una imagen", type=["jpg", "png", "jpeg"])
68
+ if entrada_imagen:
69
+ imagen = Image.open(entrada_imagen)
70
+ st.image(imagen, caption='Imagen subida.', use_column_width=True)
71
+ with st.spinner("Procesando imagen..."):
72
+ respuesta = procesar_imagen(imagen)
73
+ espacio_contenido_generado.write(f"**Respuesta de la imagen:** {respuesta}")
74
+
75
+ st.write("¡Gracias por usar el ChatBot! 😊")