Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
|
3 |
+
# Pexels API ์ค์
|
4 |
+
API_KEY = '์ฌ๊ธฐ์_๋น์ ์_API_ํค๋ฅผ_์
๋ ฅํ์ธ์'
|
5 |
+
API_ENDPOINT = 'https://api.pexels.com/v1/search'
|
6 |
+
|
7 |
+
def fetch_images(keyword, total_images=80):
|
8 |
+
headers = {
|
9 |
+
'Authorization': API_KEY
|
10 |
+
}
|
11 |
+
params = {
|
12 |
+
'query': keyword,
|
13 |
+
'per_page': total_images
|
14 |
+
}
|
15 |
+
response = requests.get(API_ENDPOINT, headers=headers, params=params)
|
16 |
+
if response.status_code == 200:
|
17 |
+
data = response.json()
|
18 |
+
images = [photo['src']['original'] for photo in data['photos']]
|
19 |
+
return images
|
20 |
+
else:
|
21 |
+
print("Error:", response.status_code)
|
22 |
+
return []
|
23 |
+
|
24 |
+
if __name__ == "__main__":
|
25 |
+
keyword = input("๊ฒ์ํ ํค์๋๋ฅผ ์
๋ ฅํ์ธ์: ")
|
26 |
+
images = fetch_images(keyword)
|
27 |
+
for i, image in enumerate(images, start=1):
|
28 |
+
print(f"{i}: {image}")
|