Spaces:
Runtime error
Runtime error
JuanjoRosquete
commited on
Commit
•
b73c954
1
Parent(s):
e8046ba
Add application file
Browse files
app.py
CHANGED
@@ -1,7 +1,36 @@
|
|
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
import gradio as gr
|
3 |
+
import torch
|
4 |
+
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
|
5 |
|
6 |
+
model_id = "stabilityai/stable-diffusion-2"
|
|
|
7 |
|
8 |
+
scheduler = EulerDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
|
9 |
+
image_model = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, torch_dtype=torch.float16)
|
10 |
+
image_model = image_model.to("cuda")
|
11 |
+
|
12 |
+
model = pipeline("automatic-speech-recognition","facebook/wav2vec2-large-xlsr-53-spanish")
|
13 |
+
|
14 |
+
def transcribe_text_audio(mic=None, file=None):
|
15 |
+
if mic is not None:
|
16 |
+
audio = mic
|
17 |
+
elif file is not None:
|
18 |
+
audio = file
|
19 |
+
else:
|
20 |
+
return "No se ha detectado ninguna entrada de audio"
|
21 |
+
transcription = model(audio)["text"]
|
22 |
+
|
23 |
+
image = image_model(transcription).images[0]
|
24 |
+
|
25 |
+
image = image.convert("RGB")
|
26 |
+
return transcription, image
|
27 |
+
|
28 |
+
|
29 |
+
gr.Interface(
|
30 |
+
fn=transcribe_text_audio,
|
31 |
+
inputs=[
|
32 |
+
gr.Audio(sources=["microphone"], type="filepath"),
|
33 |
+
gr.Audio(sources=["upload"], type="filepath"),
|
34 |
+
],
|
35 |
+
outputs=["text", "image"],
|
36 |
+
).launch()
|