fffiloni's picture
Update app.py
79b4496
raw
history blame
1.57 kB
import gradio as gr
caption = gr.Blocks.load(name="spaces/SRDdev/Image-Caption")
audio_gen = gr.Blocks.load(name="spaces/haoheliu/audioldm-text-to-audio-generation")
def infer(image_input):
cap = caption(image_input, fn_index=0)
sound = audio_gen(cap, 5, 2.5, 45, 3, fn_index=0)
return sound
title = """
<div style="text-align: center; max-width: 700px; margin: 0 auto;">
<div
style="
display: inline-flex;
align-items: center;
gap: 0.8rem;
font-size: 1.75rem;
"
>
<h1 style="font-weight: 900; margin-bottom: 7px; margin-top: 5px;">
Image to Sound Effect
</h1>
</div>
<p style="margin-bottom: 10px; font-size: 94%">
Convert an image to corresponding sound effect through AudioLDM
</p>
</div>
"""
article = """
<div class="footer">
<p>
Follow <a href="https://twitter.com/fffiloni" target="_blank">Sylvain Filoni</a> for future updates πŸ€—
</p>
</div>
"""
with gr.Blocks(css="style.css") as demo:
with gr.Column(elem_id="col-container"):
gr.HTML(title)
input_img = gr.Image(type="filepath", elem_id="input-img")
sound_output = gr.Video(label="Result", elem_id="sound-output")
generate = gr.Button("Generate Music from Image")
gr.HTML(article)
generate.click(infer, inputs=[input_img], outputs=[sound_output], api_name="i2m")
demo.queue(max_size=32, concurrency_count=20).launch()