Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,51 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# ํ์ด์ง ์ค์
|
4 |
st.set_page_config(page_title="ViDraft", layout="wide")
|
|
|
1 |
import streamlit as st
|
2 |
+
import requests
|
3 |
+
|
4 |
+
# Pexels API ํค ์ค์
|
5 |
+
PEXELS_API_KEY = "5woz23MGx1QrSY0WHFb0BRi29JvbXPu97Hg0xnklYgHUI8G0w23FKH62"
|
6 |
+
|
7 |
+
def search_image(keyword):
|
8 |
+
"""์ด๋ฏธ์ง ๊ฒ์ ํจ์"""
|
9 |
+
url = f"https://api.pexels.com/v1/search?query={keyword}+query&per_page=1"
|
10 |
+
headers = {"Authorization": PEXELS_API_KEY}
|
11 |
+
response = requests.get(url, headers=headers).json()
|
12 |
+
if response["photos"]:
|
13 |
+
# ๊ณ ํด์๋ ์ด๋ฏธ์ง URL ๋ฐํ
|
14 |
+
return response["photos"][0]["src"]["original"]
|
15 |
+
return ""
|
16 |
+
|
17 |
+
def search_video(keyword):
|
18 |
+
"""๋น๋์ค ๊ฒ์ ํจ์"""
|
19 |
+
url = f"https://api.pexels.com/videos/search?query={keyword}+query&per_page=1"
|
20 |
+
headers = {"Authorization": PEXELS_API_KEY}
|
21 |
+
response = requests.get(url, headers=headers).json()
|
22 |
+
if response["videos"]:
|
23 |
+
# ๊ณ ํด์๋ ๋น๋์ค URL ๋ฐํ
|
24 |
+
return response["videos"][0]["video_files"][0]["link"]
|
25 |
+
return ""
|
26 |
+
|
27 |
+
# 'Search Image' ๋ฉ๋ด ์ ํ ์ ์ฒ๋ฆฌ ๋ก์ง
|
28 |
+
if selected_menu == "Free Stock" and st.session_state['current_sub_menu'] == "Search Image":
|
29 |
+
keyword = st.text_input("Enter a keyword to search for images")
|
30 |
+
if keyword:
|
31 |
+
image_url = search_image(keyword)
|
32 |
+
if image_url:
|
33 |
+
st.image(image_url)
|
34 |
+
else:
|
35 |
+
st.write("No results found.")
|
36 |
+
|
37 |
+
# 'Search Video' ๋ฉ๋ด ์ ํ ์ ์ฒ๋ฆฌ ๋ก์ง
|
38 |
+
if selected_menu == "Free Stock" and st.session_state['current_sub_menu'] == "Search Video":
|
39 |
+
keyword = st.text_input("Enter a keyword to search for videos")
|
40 |
+
if keyword:
|
41 |
+
video_url = search_video(keyword)
|
42 |
+
if video_url:
|
43 |
+
st.video(video_url)
|
44 |
+
else:
|
45 |
+
st.write("No results found.")
|
46 |
+
|
47 |
+
|
48 |
+
|
49 |
|
50 |
# ํ์ด์ง ์ค์
|
51 |
st.set_page_config(page_title="ViDraft", layout="wide")
|