Spaces:
Build error
Build error
arxivgpt kim
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,21 @@ import json
|
|
| 4 |
import re
|
| 5 |
from moviepy.editor import VideoFileClip
|
| 6 |
from moviepy.audio.AudioClip import AudioClip
|
|
|
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def extract_audio(video_in):
|
| 9 |
input_video = video_in
|
| 10 |
output_audio = 'audio.wav'
|
|
@@ -136,24 +150,47 @@ css="""
|
|
| 136 |
}
|
| 137 |
"""
|
| 138 |
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
]
|
| 143 |
|
| 144 |
-
with gr.Blocks() as
|
| 145 |
with gr.Column():
|
| 146 |
-
gr.Markdown("### Image
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
submit_btn.click(
|
| 153 |
fn=infer,
|
| 154 |
inputs=[image_in, chosen_model],
|
| 155 |
-
outputs=audio_o
|
| 156 |
)
|
| 157 |
|
| 158 |
-
|
| 159 |
-
demo.launch(examples=image_examples, debug=True)
|
|
|
|
| 4 |
import re
|
| 5 |
from moviepy.editor import VideoFileClip
|
| 6 |
from moviepy.audio.AudioClip import AudioClip
|
| 7 |
+
import requests
|
| 8 |
|
| 9 |
+
def search_pexels_images(query):
|
| 10 |
+
API_KEY = '5woz23MGx1QrSY0WHFb0BRi29JvbXPu97Hg0xnklYgHUI8G0w23FKH62' # Pexels API 키를 여기에 입력하세요.
|
| 11 |
+
url = f"https://api.pexels.com/v1/search?query={query}&per_page=5" # 검색 결과 5개만 가져옵니다.
|
| 12 |
+
|
| 13 |
+
headers = {
|
| 14 |
+
"Authorization": API_KEY
|
| 15 |
+
}
|
| 16 |
+
response = requests.get(url, headers=headers)
|
| 17 |
+
data = response.json()
|
| 18 |
+
|
| 19 |
+
images_urls = [photo['src']['medium'] for photo in data['photos']]
|
| 20 |
+
return images_urls
|
| 21 |
+
|
| 22 |
def extract_audio(video_in):
|
| 23 |
input_video = video_in
|
| 24 |
output_audio = 'audio.wav'
|
|
|
|
| 150 |
}
|
| 151 |
"""
|
| 152 |
|
| 153 |
+
def show_search_results(query):
|
| 154 |
+
images_urls = search_pexels_images(query)
|
| 155 |
+
return images_urls
|
|
|
|
| 156 |
|
| 157 |
+
with gr.Blocks() as app:
|
| 158 |
with gr.Column():
|
| 159 |
+
gr.Markdown("### Image SFX Generator with Pexels Image Search")
|
| 160 |
+
search_query = gr.Textbox(label="사진 검색")
|
| 161 |
+
search_btn = gr.Button("검색")
|
| 162 |
+
images_output = gr.Gallery(label="검색 결과 이미지")
|
| 163 |
+
|
| 164 |
+
search_btn.click(
|
| 165 |
+
fn=show_search_results,
|
| 166 |
+
inputs=search_query,
|
| 167 |
+
outputs=images_output
|
| 168 |
+
)
|
| 169 |
+
app.launch(debug=True)
|
| 170 |
+
|
| 171 |
+
with gr.Blocks(css=css) as demo:
|
| 172 |
+
with gr.Column(elem_id="col-container"):
|
| 173 |
+
gr.HTML("""
|
| 174 |
+
<h2 style="text-align: center;">
|
| 175 |
+
Image to SFX
|
| 176 |
+
</h2>
|
| 177 |
+
<p style="text-align: center;">
|
| 178 |
+
Compare MAGNet, AudioLDM2 and AudioGen sound effects generation from image caption.
|
| 179 |
+
</p>
|
| 180 |
+
""")
|
| 181 |
+
|
| 182 |
+
with gr.Column():
|
| 183 |
+
image_in = gr.Image(sources=["upload"], type="filepath", label="Image input", value="oiseau.png")
|
| 184 |
+
with gr.Row():
|
| 185 |
+
chosen_model = gr.Radio(label="Choose a model", choices=["MAGNet", "AudioLDM-2", "AudioGen"], value="AudioLDM-2")
|
| 186 |
+
submit_btn = gr.Button("Submit")
|
| 187 |
+
with gr.Column():
|
| 188 |
+
audio_o = gr.Audio(label="Audio output")
|
| 189 |
+
|
| 190 |
submit_btn.click(
|
| 191 |
fn=infer,
|
| 192 |
inputs=[image_in, chosen_model],
|
| 193 |
+
outputs=[audio_o]
|
| 194 |
)
|
| 195 |
|
| 196 |
+
demo.queue(max_size=10).launch(debug=True)
|
|
|