Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
from diffusers import DiffusionPipeline
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
pipe1 = pipeline("automatic-speech-recognition", model="openai/whisper-base")
|
| 9 |
+
pipe2 = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 10 |
+
pipe3 = DiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5")
|
| 11 |
+
|
| 12 |
+
def audio_to_image(audio):
|
| 13 |
+
transcription = pipe1(audio)["text"]
|
| 14 |
+
|
| 15 |
+
summary = pipe2(transcription, max_length=30, min_length=10, do_sample=False)
|
| 16 |
+
summary_text = summary[0]['summary_text']
|
| 17 |
+
|
| 18 |
+
prompt = summary_text
|
| 19 |
+
image = pipe3(prompt).images[0]
|
| 20 |
+
|
| 21 |
+
return image
|
| 22 |
+
|
| 23 |
+
demo = gr.Interface(fn=audio_to_image, inputs=gr.Audio(source="upload"), outputs="image")
|
| 24 |
+
demo.launch(share=True)
|