ckfrpark commited on
Commit
36bbe72
1 Parent(s): 1b2fce6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -1,25 +1,24 @@
 
1
  import requests
2
 
3
  # Pexels API 키 설정
4
  API_KEY = 'XDDeRl6U3IY8VRzv7YBGRrnGuOwqpOYD2yS9VTAYM7VEfZcr1aWXubZ1'
5
  API_ENDPOINT = 'https://api.pexels.com/v1/search'
6
 
7
- def fetch_high_quality_images(keyword, per_page=80):
8
- headers = {
9
- 'Authorization': API_KEY
10
- }
11
- params = {
12
- 'query': keyword,
13
- 'per_page': per_page,
14
- 'size': 'large'
15
- }
16
  response = requests.get(API_ENDPOINT, headers=headers, params=params)
 
17
  if response.status_code == 200:
18
  data = response.json()
19
  images = data['photos']
20
  for image in images:
21
- print(image['src']['original'])
 
22
 
23
- if __name__ == '__main__':
24
- keyword = input("Enter keyword: ")
25
- fetch_high_quality_images(keyword)
 
 
 
1
+ import gradio as gr
2
  import requests
3
 
4
  # Pexels API 키 설정
5
  API_KEY = 'XDDeRl6U3IY8VRzv7YBGRrnGuOwqpOYD2yS9VTAYM7VEfZcr1aWXubZ1'
6
  API_ENDPOINT = 'https://api.pexels.com/v1/search'
7
 
8
+ def fetch_high_quality_images(keyword):
9
+ headers = {'Authorization': API_KEY}
10
+ params = {'query': keyword, 'per_page': 80, 'size': 'large'}
 
 
 
 
 
 
11
  response = requests.get(API_ENDPOINT, headers=headers, params=params)
12
+ images_urls = []
13
  if response.status_code == 200:
14
  data = response.json()
15
  images = data['photos']
16
  for image in images:
17
+ images_urls.append(image['src']['original'])
18
+ return images_urls
19
 
20
+ def show_images(keyword):
21
+ urls = fetch_high_quality_images(keyword)
22
+ return [gr.Image(src=url) for url in urls]
23
+
24
+ interface = gr.Interface(fn=show_images, inputs=gr.Textbox(label="Enter Keyword"), outputs=gr.Gallery()).launch()