Spaces:
Running
Running
File size: 1,084 Bytes
a51cbe1 d3cb1f3 16ca3cf d3cb1f3 4d300d7 d3cb1f3 0e0f707 d3cb1f3 0e0f707 d3cb1f3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
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)
|