iespsurmreqmer commited on
Commit
44aa1b2
·
1 Parent(s): ccf1cc9
Files changed (1) hide show
  1. app4.py +15 -18
app4.py CHANGED
@@ -1,42 +1,39 @@
1
  import streamlit as st
2
  import requests
3
- import base64
4
  import os
5
  from dotenv import load_dotenv
6
 
7
- # Cargar variables del .env
8
  load_dotenv()
9
 
10
- API_URL = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits"
11
- HF_TOKEN = os.getenv("TOKEN") # ← OBTENIDO DESDE .env
12
-
13
  if HF_TOKEN is None:
14
- st.error("❌ ERROR: No se encontró la variable TOKEN en el .env")
15
  st.stop()
16
 
 
17
  headers = {"Authorization": f"Bearer {HF_TOKEN}"}
18
 
19
  def text_to_speech(text):
20
  payload = {"inputs": text}
21
  response = requests.post(API_URL, headers=headers, json=payload)
22
- return response.content
23
 
24
- st.title("Texto a Voz Accesible")
25
- st.write("Aplicación para personas con discapacidades visuales o cognitivas.")
26
 
27
- texto = st.text_area("Escribe el texto que quieres convertir a audio")
28
 
29
- if st.button("Generar Audio"):
30
- if texto.strip() == "":
31
- st.warning("Introduce texto para convertir.")
32
  else:
33
  audio_bytes = text_to_speech(texto)
34
 
35
  st.audio(audio_bytes, format="audio/wav")
36
 
37
  st.download_button(
38
- label="Descargar audio",
39
- data=audio_bytes,
40
- file_name="voz_generada.wav",
41
- mime="audio/wav",
42
- )
 
1
  import streamlit as st
2
  import requests
 
3
  import os
4
  from dotenv import load_dotenv
5
 
 
6
  load_dotenv()
7
 
8
+ HF_TOKEN = os.getenv("TOKEN")
 
 
9
  if HF_TOKEN is None:
10
+ st.error("❌ La variable TOKEN no está definida en .env")
11
  st.stop()
12
 
13
+ API_URL = "https://api-inference.huggingface.co/models/facebook/mms-tts-eng"
14
  headers = {"Authorization": f"Bearer {HF_TOKEN}"}
15
 
16
  def text_to_speech(text):
17
  payload = {"inputs": text}
18
  response = requests.post(API_URL, headers=headers, json=payload)
19
+ return response.content # devuelve WAV
20
 
21
+ st.title("Texto a Voz Accesible (Inference Provider)")
22
+ st.write("Convierte texto en audio para ayudar a personas con discapacidad visual.")
23
 
24
+ texto = st.text_area("Escribe el texto para convertir")
25
 
26
+ if st.button("Generar audio"):
27
+ if not texto.strip():
28
+ st.warning("Por favor, escribe algo.")
29
  else:
30
  audio_bytes = text_to_speech(texto)
31
 
32
  st.audio(audio_bytes, format="audio/wav")
33
 
34
  st.download_button(
35
+ "Descargar WAV",
36
+ audio_bytes,
37
+ file_name="audio.wav",
38
+ mime="audio/wav"
39
+ )