Spaces:
Runtime error
Runtime error
import gradio as gr | |
from PIL import Image | |
import re | |
import os | |
import speech_recognition as sr | |
stable_diffusion = gr.Blocks.load(name="spaces/stabilityai/stable-diffusion") | |
r = sr.Recognizer() | |
def transcribe(audio): | |
with sr.AudioFile(audio) as source: | |
audio_ = r.listen(source) | |
text = r.recognize_google(audio_)#, language = 'en-IN')# , show_all=True) | |
return text | |
def get_images(prompt): | |
gallery_dir = stable_diffusion(prompt, fn_index=2) | |
return [os.path.join(gallery_dir, img) for img in os.listdir(gallery_dir)] | |
with gr.Blocks() as demo: | |
gr.Markdown("Stable diffusion magic -> Get the photo from whatever you can think of!") | |
with gr.Tab("Audio Input"): | |
audio_input = gr.Audio(source="microphone", type="filepath") | |
submit_audio_button = gr.Button("Convert to Image") | |
text_output = gr.Textbox(label="Recorded text") | |
with gr.Tab("Text Input"): | |
text_input = gr.Textbox(label="Enter text") | |
submit_button_text = gr.Button("Convert to Image") | |
# output = gr.Textbox(label="Output Box") | |
sd_output = gr.Gallery().style(grid=2, height="auto") | |
submit_audio_button.click(fn=transcribe, inputs=audio_input, outputs=text_output) | |
text_output.change(fn=get_images, inputs=text_output, outputs=sd_output) | |
submit_button_text.click(fn=get_images, inputs=text_input, outputs=sd_output) | |
demo.launch() | |