honey90 commited on
Commit
0667474
ยท
verified ยท
1 Parent(s): 3e4bcb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -21,8 +21,12 @@ def search_videos(keyword):
21
  url = "https://api.pexels.com/videos/search"
22
  response = requests.get(url, headers=headers, params=params)
23
  data = response.json()
24
- videos_urls = [video['video_files'][0]['link'] for video in data['videos']]
25
- return videos_urls
 
 
 
 
26
 
27
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
28
  with gr.Blocks() as app:
@@ -30,15 +34,15 @@ with gr.Blocks() as app:
30
  with gr.Row():
31
  image_search_input = gr.Textbox(label="Search for Images")
32
  image_search_button = gr.Button("Search")
33
- image_gallery = gr.Gallery().style(grid=[2, 2], height="auto")
34
  image_search_button.click(search_images, inputs=image_search_input, outputs=image_gallery)
35
 
36
  with gr.Tab("Videos"):
37
  with gr.Row():
38
  video_search_input = gr.Textbox(label="Search for Videos")
39
  video_search_button = gr.Button("Search")
40
- video_gallery = gr.Video().style(grid=[2, 2], height="auto")
41
- video_search_button.click(search_videos, inputs=video_search_input, outputs=video_gallery)
42
 
43
  # ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
44
  app.launch()
 
21
  url = "https://api.pexels.com/videos/search"
22
  response = requests.get(url, headers=headers, params=params)
23
  data = response.json()
24
+ # ์—ฌ๋Ÿฌ ๋น„๋””์˜ค URL ์ค‘ ์ฒซ ๋ฒˆ์งธ๋งŒ ๋ฐ˜ํ™˜
25
+ if data['videos']:
26
+ first_video_url = data['videos'][0]['video_files'][0]['link']
27
+ return first_video_url
28
+ else:
29
+ return "No videos found"
30
 
31
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
32
  with gr.Blocks() as app:
 
34
  with gr.Row():
35
  image_search_input = gr.Textbox(label="Search for Images")
36
  image_search_button = gr.Button("Search")
37
+ image_gallery = gr.Gallery() # style ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœ ์ œ๊ฑฐ
38
  image_search_button.click(search_images, inputs=image_search_input, outputs=image_gallery)
39
 
40
  with gr.Tab("Videos"):
41
  with gr.Row():
42
  video_search_input = gr.Textbox(label="Search for Videos")
43
  video_search_button = gr.Button("Search")
44
+ video_output = gr.Video() # ๋น„๋””์˜ค ๊ฐค๋Ÿฌ๋ฆฌ ๋Œ€์‹  ๋‹จ์ผ ๋น„๋””์˜ค ์ถœ๋ ฅ์œผ๋กœ ๋ณ€๊ฒฝ
45
+ video_search_button.click(search_videos, inputs=video_search_input, outputs=video_output)
46
 
47
  # ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
48
  app.launch()