seawolf2357 commited on
Commit
1c363e3
·
verified ·
1 Parent(s): c78b25e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -10
app.py CHANGED
@@ -20,14 +20,32 @@ def search_images(keyword):
20
  image_urls = [photo['src']['original'] for photo in data['photos']]
21
  return image_urls
22
 
23
- # Gradio 인터페이스 생성
24
- iface = gr.Interface(
25
- fn=search_images,
26
- inputs=gr.Textbox(label="검색 키워드"),
27
- outputs=gr.Gallery(label="검색된 이미지"),
28
- title="Pexels 이미지 검색기",
29
- description="Pexels에서 키워드에 해당하는 고화질 이미지를 검색합니다."
30
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- # 인터페이스 실행
33
- iface.launch()
 
20
  image_urls = [photo['src']['original'] for photo in data['photos']]
21
  return image_urls
22
 
23
+ def search_videos(keyword):
24
+ headers = {
25
+ 'Authorization': PEXELS_API_KEY
26
+ }
27
+ params = {
28
+ 'query': keyword,
29
+ 'per_page': 80 # 번에 반환받을 비디오 수
30
+ }
31
+ url = 'https://api.pexels.com/videos/search'
32
+ response = requests.get(url, headers=headers, params=params)
33
+ data = response.json()
34
+
35
+ # 검색된 비디오의 URL을 리스트로 추출
36
+ video_urls = [video['video_files'][0]['link'] for video in data['videos']]
37
+ return video_urls
38
+
39
+ with gr.Blocks() as demo:
40
+ with gr.Tabs():
41
+ with gr.Tab("이미지 검색"):
42
+ image_search_input = gr.Textbox(label="검색 키워드")
43
+ image_search_output = gr.Gallery(label="검색된 이미지")
44
+ image_search_input.change(search_images, inputs=image_search_input, outputs=image_search_output)
45
+
46
+ with gr.Tab("비디오 검색"):
47
+ video_search_input = gr.Textbox(label="검색 키워드")
48
+ video_search_output = gr.Gallery(label="검색된 비디오")
49
+ video_search_input.change(search_videos, inputs=video_search_input, outputs=video_search_output)
50
 
51
+ demo.launch()