Spaces:
No application file
No application file
Commit
·
21b9e96
1
Parent(s):
1a2afdb
- .gitignore +3 -1
- app3.py +5 -4
- app4.py +36 -0
.gitignore
CHANGED
|
@@ -1,3 +1,5 @@
|
|
| 1 |
huggingvenv/
|
| 2 |
|
| 3 |
-
.venv
|
|
|
|
|
|
|
|
|
| 1 |
huggingvenv/
|
| 2 |
|
| 3 |
+
.venv
|
| 4 |
+
|
| 5 |
+
.env
|
app3.py
CHANGED
|
@@ -3,23 +3,24 @@ from diffusers import StableDiffusionPipeline
|
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
| 5 |
|
| 6 |
-
|
|
|
|
| 7 |
model_id = "OFA-Sys/small-stable-diffusion-v0"
|
| 8 |
pipe = StableDiffusionPipeline.from_pretrained(model_id)
|
| 9 |
-
pipe = pipe.to("cpu")
|
| 10 |
|
| 11 |
# Función que Gradio llamará
|
| 12 |
def generar_imagen(prompt):
|
| 13 |
if not prompt:
|
| 14 |
return None
|
| 15 |
image = pipe(prompt).images[0]
|
| 16 |
-
return image
|
| 17 |
|
| 18 |
# Interfaz Gradio
|
| 19 |
demo = gr.Interface(
|
| 20 |
fn=generar_imagen,
|
| 21 |
inputs=gr.Textbox(label="Prompt"),
|
| 22 |
-
outputs=gr.Image(type="pil"),
|
| 23 |
title="Generador de imágenes ligero",
|
| 24 |
description="Introduce un prompt y el modelo generará la imagen. Podrás descargarla con el botón de Gradio."
|
| 25 |
)
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
| 5 |
|
| 6 |
+
|
| 7 |
+
#Modelo que genera imágenes, está poco probado ya que tarda muchísimo en generarlas
|
| 8 |
model_id = "OFA-Sys/small-stable-diffusion-v0"
|
| 9 |
pipe = StableDiffusionPipeline.from_pretrained(model_id)
|
| 10 |
+
pipe = pipe.to("cpu")
|
| 11 |
|
| 12 |
# Función que Gradio llamará
|
| 13 |
def generar_imagen(prompt):
|
| 14 |
if not prompt:
|
| 15 |
return None
|
| 16 |
image = pipe(prompt).images[0]
|
| 17 |
+
return image
|
| 18 |
|
| 19 |
# Interfaz Gradio
|
| 20 |
demo = gr.Interface(
|
| 21 |
fn=generar_imagen,
|
| 22 |
inputs=gr.Textbox(label="Prompt"),
|
| 23 |
+
outputs=gr.Image(type="pil"),
|
| 24 |
title="Generador de imágenes ligero",
|
| 25 |
description="Introduce un prompt y el modelo generará la imagen. Podrás descargarla con el botón de Gradio."
|
| 26 |
)
|
app4.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 10 |
+
def text_to_speech(text):
|
| 11 |
+
payload = {"inputs": text}
|
| 12 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 13 |
+
return response.content
|
| 14 |
+
|
| 15 |
+
st.title("Texto a Voz Accesible")
|
| 16 |
+
st.write("Aplicación para personas con discapacidades visuales o cognitivas.")
|
| 17 |
+
|
| 18 |
+
texto = st.text_area("Escribe el texto que quieres convertir a audio")
|
| 19 |
+
|
| 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 |
+
)
|