Image2Audio / app.py
arxivgpt kim
Update app.py
a51cbe1 verified
raw
history blame
1.08 kB
import gradio as gr
import requests
def search_pexels_images(query):
API_KEY = '5woz23MGx1QrSY0WHFb0BRi29JvbXPu97Hg0xnklYgHUI8G0w23FKH62' # Pexels API 키를 여기에 입력하세요.
url = f"https://api.pexels.com/v1/search?query={query}&per_page=5" # 검색 결과 5개만 가져옵니다.
headers = {
"Authorization": API_KEY
}
response = requests.get(url, headers=headers)
data = response.json()
images_urls = [photo['src']['medium'] for photo in data['photos']]
return images_urls
def show_search_results(query):
images_urls = search_pexels_images(query)
return images_urls
with gr.Blocks() as app:
with gr.Column():
gr.Markdown("### Image SFX Generator with Pexels Image Search")
search_query = gr.Textbox(label="사진 검색")
search_btn = gr.Button("검색")
images_output = gr.Gallery(label="검색 결과 이미지")
search_btn.click(
fn=show_search_results,
inputs=search_query,
outputs=images_output
)
app.launch(debug=True)