iespsurmreqmer commited on
Commit
23f321d
·
1 Parent(s): 21b9e96
Files changed (2) hide show
  1. app4.py +11 -5
  2. requirements.txt +4 -1
app4.py CHANGED
@@ -1,9 +1,18 @@
1
  import streamlit as st
2
  import requests
3
  import base64
 
 
 
 
 
4
 
5
  API_URL = "https://api-inference.huggingface.co/models/espnet/kan-bayashi_ljspeech_vits"
6
- HF_TOKEN = "TU_TOKEN_DE_HUGGINGFACE" # pon tu token aquí
 
 
 
 
7
 
8
  headers = {"Authorization": f"Bearer {HF_TOKEN}"}
9
 
@@ -20,17 +29,14 @@ texto = st.text_area("Escribe el texto que quieres convertir a audio")
20
  if st.button("Generar Audio"):
21
  if texto.strip() == "":
22
  st.warning("Introduce texto para convertir.")
23
-
24
  else:
25
  audio_bytes = text_to_speech(texto)
26
 
27
- # Mostrar audio en la web
28
  st.audio(audio_bytes, format="audio/wav")
29
 
30
- # Botón de descarga
31
  st.download_button(
32
  label="Descargar audio",
33
  data=audio_bytes,
34
  file_name="voz_generada.wav",
35
  mime="audio/wav",
36
- )
 
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
 
 
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
+ )
requirements.txt CHANGED
@@ -2,4 +2,7 @@ gradio
2
  transformers==4.49.0
3
  torch==2.6.0
4
  diffusers
5
- Pillow
 
 
 
 
2
  transformers==4.49.0
3
  torch==2.6.0
4
  diffusers
5
+ Pillow
6
+ streamlit
7
+ requests
8
+ python-dotenv