Josedcape commited on
Commit
91bb02a
verified
1 Parent(s): e2047c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -3
app.py CHANGED
@@ -16,7 +16,8 @@ import requests
16
  # Configuraci贸n de la clave API
17
  load_dotenv()
18
  openai.api_key = os.getenv("OPENAI_API_KEY")
19
- os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "path/to/your/google-cloud-credentials.json"
 
20
 
21
  # Inicializaci贸n de Vertex AI
22
  vertexai.init(project="your-project-id", location="us-central1") # Reemplaza "your-project-id" y "us-central1"
@@ -75,7 +76,7 @@ st.markdown(
75
  )
76
 
77
  # Encabezado
78
- st.image("biblie.jpg")
79
  st.title("馃摉 LOS C脫DIGOS DE DIOS - BOTIDINAMIX AI")
80
  st.markdown("Bienvenido al Asistente Teol贸gico, donde puedes preguntar sobre interpretaciones y reflexiones b铆blicas.")
81
 
@@ -162,7 +163,6 @@ elif page == "Generador de Frases B铆blicas":
162
 
163
  # Funci贸n para generar una imagen alusiva usando Pexels
164
  def generar_imagen(frase):
165
- PEXELS_API_KEY = os.getenv("sWMvMKk7Mvv5o6Q90XGMfP2vliUiagc9rESBAO9DVZQdmlcla0LMJ8O3")
166
  headers = {
167
  "Authorization": f"Bearer {PEXELS_API_KEY}"
168
  }
@@ -205,3 +205,59 @@ elif page == "Generador de Frases B铆blicas":
205
  else:
206
  st.warning("Por favor, ingresa un vers铆culo o una palabra antes de generar.")
207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  # Configuraci贸n de la clave API
17
  load_dotenv()
18
  openai.api_key = os.getenv("OPENAI_API_KEY")
19
+ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "botidinamix-g.json"
20
+ PEXELS_API_KEY = os.getenv("sWMvMKk7Mvv5o6Q90XGMfP2vliUiagc9rESBAO9DVZQdmlcla0LMJ8O3")
21
 
22
  # Inicializaci贸n de Vertex AI
23
  vertexai.init(project="your-project-id", location="us-central1") # Reemplaza "your-project-id" y "us-central1"
 
76
  )
77
 
78
  # Encabezado
79
+ st.image("biblia.jpg")
80
  st.title("馃摉 LOS C脫DIGOS DE DIOS - BOTIDINAMIX AI")
81
  st.markdown("Bienvenido al Asistente Teol贸gico, donde puedes preguntar sobre interpretaciones y reflexiones b铆blicas.")
82
 
 
163
 
164
  # Funci贸n para generar una imagen alusiva usando Pexels
165
  def generar_imagen(frase):
 
166
  headers = {
167
  "Authorization": f"Bearer {PEXELS_API_KEY}"
168
  }
 
205
  else:
206
  st.warning("Por favor, ingresa un vers铆culo o una palabra antes de generar.")
207
 
208
+ # Funci贸n para obtener respuesta de OpenAI
209
+ def obtener_respuesta(pregunta, modelo="gpt-4", temperatura=0.5):
210
+ response = openai.ChatCompletion.create(
211
+ model=modelo,
212
+ messages=[{"role": "system", "content": "You are a knowledgeable theological assistant."},
213
+ {"role": "user", "content": pregunta}],
214
+ temperature=temperatura,
215
+ max_tokens=150,
216
+ )
217
+ respuesta = response['choices'][0]['message']['content']
218
+ return respuesta
219
+
220
+ # Funci贸n para convertir texto a voz usando Google Cloud Text-to-Speech
221
+ def text_to_speech(text):
222
+ client = texttospeech.TextToSpeechClient()
223
+ synthesis_input = texttospeech.SynthesisInput(text=text)
224
+ voice = texttospeech.VoiceSelectionParams(language_code="es-ES", ssml_gender=texttospeech.SsmlVoiceGender.NEUTRAL)
225
+ audio_config = texttospeech.AudioConfig(audio_encoding=texttospeech.AudioEncoding.MP3)
226
+ response = client.synthesize_speech(input=synthesis_input, voice=voice, audio_config=audio_config)
227
+ audio_path = tempfile.NamedTemporaryFile(delete=False, suffix=".mp3").name
228
+ with open(audio_path, "wb") as out:
229
+ out.write(response.audio_content)
230
+ return audio_path
231
+
232
+ # Funci贸n para convertir texto a voz y devolver base64
233
+ def text_to_speech_base64(text):
234
+ client = texttospeech.TextToSpeechClient()
235
+ synthesis_input = texttospeech.SynthesisInput(text=text)
236
+ voice = texttospeech.VoiceSelectionParams(language_code="es-ES", ssml_gender=texttospeech.SsmlVoiceGender.NEUTRAL)
237
+ audio_config = texttospeech.AudioConfig(audio_encoding=texttospeech.AudioEncoding.MP3)
238
+ response = client.synthesize_speech(input=synthesis_input, voice=voice, audio_config=audio_config)
239
+ audio_base64 = base64.b64encode(response.audio_content).decode('utf-8')
240
+ return audio_base64
241
+
242
+ # Clase para procesar audio
243
+ class AudioProcessor(AudioProcessorBase):
244
+ def __init__(self):
245
+ self.audio_bytes = b''
246
+
247
+ def recv(self, frame):
248
+ self.audio_bytes += frame.to_ndarray().tobytes()
249
+ return frame
250
+
251
+ # Funci贸n para transcribir audio a texto usando Google Cloud Speech-to-Text
252
+ def transcribir_audio(audio_bytes):
253
+ client = SpeechClient()
254
+ audio = RecognitionAudio(content=audio_bytes)
255
+ config = RecognitionConfig(
256
+ encoding=RecognitionConfig.AudioEncoding.LINEAR16,
257
+ sample_rate_hertz=16000,
258
+ language_code="es-ES",
259
+ )
260
+ response = client.recognize(config=config, audio=audio)
261
+ for result in response.results:
262
+ return result.alternatives[0].transcript
263
+ return ""