Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ from share_btn import community_icon_html, loading_icon_html, share_js
|
|
6 |
|
7 |
token = os.environ.get('HF_TOKEN')
|
8 |
caption = gr.Blocks.load(name="spaces/laion/CoCa")
|
9 |
-
audio_gen = gr.Blocks.load(name="spaces/haoheliu/audioldm-text-to-audio-generation)
|
10 |
|
11 |
ph_message="If you're not happy with sound result, you can manually describe the scene depicted in your image :)"
|
12 |
|
@@ -19,7 +19,7 @@ def input_changes(input_img):
|
|
19 |
print("CoCa caption: '" + cap + "' β’ ")
|
20 |
ph_update = "CoCa caption: '" + cap + "' β’ "
|
21 |
|
22 |
-
return manual_cap.update(value="",placeholder=f"{ph_update}{ph_message}"), caption_output.update(value=cap),
|
23 |
|
24 |
def infer(image_input, manual_caption, duration_in, seed, caption_output):
|
25 |
|
@@ -36,9 +36,14 @@ def infer(image_input, manual_caption, duration_in, seed, caption_output):
|
|
36 |
|
37 |
sound = audio_gen(cap, duration_in, 2.5, seed, 3, fn_index=0)
|
38 |
print(sound)
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
40 |
#return cap, sound[1], gr.Textbox.update(placeholder=f"{ph_update}{ph_message}"), gr.Group.update(visible=True)
|
41 |
-
return cap, sound, gr.Group.update(visible=True)
|
42 |
|
43 |
title = """
|
44 |
<div style="text-align: center; max-width: 700px; margin: 0 auto;">
|
@@ -104,8 +109,8 @@ with gr.Blocks(css="style.css") as demo:
|
|
104 |
seed_in = gr.Slider(label="Seed", value=440, minimum=45, maximum=10000, step=1)
|
105 |
|
106 |
caption_output = gr.Textbox(label="Caption", visible=False, elem_id="text-caption")
|
107 |
-
|
108 |
-
debug = gr.Textbox()
|
109 |
generate = gr.Button("Generate SFX from Image")
|
110 |
|
111 |
with gr.Group(elem_id="share-btn-container", visible=False) as share_group:
|
@@ -120,7 +125,7 @@ with gr.Blocks(css="style.css") as demo:
|
|
120 |
|
121 |
|
122 |
|
123 |
-
generate.click(infer, inputs=[input_img, manual_cap, duration_in, seed_in, caption_output], outputs=[caption_output,
|
124 |
share_button.click(None, [], [], _js=share_js)
|
125 |
|
126 |
demo.queue(max_size=32).launch(debug=True)
|
|
|
6 |
|
7 |
token = os.environ.get('HF_TOKEN')
|
8 |
caption = gr.Blocks.load(name="spaces/laion/CoCa")
|
9 |
+
audio_gen = gr.Blocks.load(name="spaces/haoheliu/audioldm-text-to-audio-generation")
|
10 |
|
11 |
ph_message="If you're not happy with sound result, you can manually describe the scene depicted in your image :)"
|
12 |
|
|
|
19 |
print("CoCa caption: '" + cap + "' β’ ")
|
20 |
ph_update = "CoCa caption: '" + cap + "' β’ "
|
21 |
|
22 |
+
return manual_cap.update(value="",placeholder=f"{ph_update}{ph_message}"), caption_output.update(value=cap), sound_output.update(value=None)
|
23 |
|
24 |
def infer(image_input, manual_caption, duration_in, seed, caption_output):
|
25 |
|
|
|
36 |
|
37 |
sound = audio_gen(cap, duration_in, 2.5, seed, 3, fn_index=0)
|
38 |
print(sound)
|
39 |
+
|
40 |
+
|
41 |
+
video = VideoFileClip(sound)
|
42 |
+
audio = video.audio
|
43 |
+
|
44 |
+
audio.write_audiofile("sound.mp3")
|
45 |
#return cap, sound[1], gr.Textbox.update(placeholder=f"{ph_update}{ph_message}"), gr.Group.update(visible=True)
|
46 |
+
return cap, "sound.mp3", gr.Group.update(visible=True)
|
47 |
|
48 |
title = """
|
49 |
<div style="text-align: center; max-width: 700px; margin: 0 auto;">
|
|
|
109 |
seed_in = gr.Slider(label="Seed", value=440, minimum=45, maximum=10000, step=1)
|
110 |
|
111 |
caption_output = gr.Textbox(label="Caption", visible=False, elem_id="text-caption")
|
112 |
+
sound_output = gr.Audio(label="Result", elem_id="sound-output")
|
113 |
+
#debug = gr.Textbox()
|
114 |
generate = gr.Button("Generate SFX from Image")
|
115 |
|
116 |
with gr.Group(elem_id="share-btn-container", visible=False) as share_group:
|
|
|
125 |
|
126 |
|
127 |
|
128 |
+
generate.click(infer, inputs=[input_img, manual_cap, duration_in, seed_in, caption_output], outputs=[caption_output, sound_output, share_group], api_name="i2fx")
|
129 |
share_button.click(None, [], [], _js=share_js)
|
130 |
|
131 |
demo.queue(max_size=32).launch(debug=True)
|