Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
3 |
-
import speech_recognition as sr
|
4 |
import google.generativeai as genai
|
5 |
from gtts import gTTS
|
6 |
import os
|
@@ -12,31 +11,32 @@ st.set_page_config(layout="wide")
|
|
12 |
api_key = "AIzaSyDJZ3r6VRhRivR0pb96cBRg_VvGg_fXq5k" # API key proporcionada
|
13 |
|
14 |
def procesar_texto(texto):
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
def procesar_imagen(imagen):
|
21 |
-
genai.configure(api_key=api_key)
|
22 |
-
modelo = genai.GenerativeModel('gemini-1.5-pro-latest')
|
23 |
-
respuesta = modelo.generate_content(imagen.name)
|
24 |
-
return respuesta.text
|
25 |
-
|
26 |
-
def reconocer_voz():
|
27 |
try:
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
except sr.RequestError as e:
|
37 |
-
return f"No se pudieron solicitar resultados del servicio de reconocimiento de voz de Google; {e}"
|
38 |
except Exception as e:
|
39 |
-
|
|
|
40 |
|
41 |
def hablar_texto(texto):
|
42 |
try:
|
@@ -59,7 +59,7 @@ with open("./style.css") as f:
|
|
59 |
col1, col2 = st.columns([1, 3])
|
60 |
|
61 |
with col1:
|
62 |
-
tipo_entrada = st.selectbox("Selecciona el tipo de entrada", ["Haz una pregunta❓", "🖼️ Subir imagen"
|
63 |
|
64 |
with col2:
|
65 |
if tipo_entrada == "Haz una pregunta❓":
|
@@ -80,13 +80,3 @@ with col2:
|
|
80 |
respuesta = procesar_imagen(entrada_imagen)
|
81 |
espacio_contenido_generado.write(respuesta)
|
82 |
|
83 |
-
elif tipo_entrada == "🎤 Usar micrófono":
|
84 |
-
if st.button("Grabar"):
|
85 |
-
texto_de_voz = reconocer_voz()
|
86 |
-
st.text_input("Texto reconocido", value=texto_de_voz) # Muestra el texto reconocido
|
87 |
-
if texto_de_voz:
|
88 |
-
with st.spinner("Generando respuesta..."):
|
89 |
-
resultado = procesar_texto(texto_de_voz)
|
90 |
-
espacio_contenido_generado.write(resultado)
|
91 |
-
if st.button("🔊 Hablar", key="hablar_entrada_voz"):
|
92 |
-
hablar_texto(resultado)
|
|
|
1 |
import streamlit as st
|
2 |
from PIL import Image
|
|
|
3 |
import google.generativeai as genai
|
4 |
from gtts import gTTS
|
5 |
import os
|
|
|
11 |
api_key = "AIzaSyDJZ3r6VRhRivR0pb96cBRg_VvGg_fXq5k" # API key proporcionada
|
12 |
|
13 |
def procesar_texto(texto):
|
14 |
+
try:
|
15 |
+
genai.configure(api_key=api_key)
|
16 |
+
modelo = genai.GenerativeModel('gemini-1.5-pro-latest')
|
17 |
+
respuesta = modelo.generate_content(texto)
|
18 |
+
# Verifica si la respuesta contiene la propiedad `text`
|
19 |
+
if hasattr(respuesta, 'text'):
|
20 |
+
return respuesta.text
|
21 |
+
else:
|
22 |
+
return "No se pudo generar una respuesta válida."
|
23 |
+
except Exception as e:
|
24 |
+
st.error(f"Error al procesar el texto: {e}")
|
25 |
+
return "No se pudo generar una respuesta."
|
26 |
|
27 |
def procesar_imagen(imagen):
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
try:
|
29 |
+
genai.configure(api_key=api_key)
|
30 |
+
modelo = genai.GenerativeModel('gemini-1.5-pro-latest')
|
31 |
+
respuesta = modelo.generate_content(imagen.name)
|
32 |
+
# Verifica si la respuesta contiene la propiedad `text`
|
33 |
+
if hasattr(respuesta, 'text'):
|
34 |
+
return respuesta.text
|
35 |
+
else:
|
36 |
+
return "No se pudo procesar la imagen correctamente."
|
|
|
|
|
37 |
except Exception as e:
|
38 |
+
st.error(f"Error al procesar la imagen: {e}")
|
39 |
+
return "No se pudo procesar la imagen."
|
40 |
|
41 |
def hablar_texto(texto):
|
42 |
try:
|
|
|
59 |
col1, col2 = st.columns([1, 3])
|
60 |
|
61 |
with col1:
|
62 |
+
tipo_entrada = st.selectbox("Selecciona el tipo de entrada", ["Haz una pregunta❓", "🖼️ Subir imagen"])
|
63 |
|
64 |
with col2:
|
65 |
if tipo_entrada == "Haz una pregunta❓":
|
|
|
80 |
respuesta = procesar_imagen(entrada_imagen)
|
81 |
espacio_contenido_generado.write(respuesta)
|
82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|