Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,29 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import requests
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
-
CX = '56b34994f47704ddd'
|
8 |
-
URL = f"https://www.googleapis.com/customsearch/v1?q={query}&cx={CX}&searchType=image&key={API_KEY}"
|
9 |
-
|
10 |
-
response = requests.get(URL)
|
11 |
-
results = response.json()
|
12 |
-
image_urls = []
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
17 |
|
18 |
-
#
|
19 |
-
|
|
|
|
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
27 |
|
28 |
-
# ์ธํฐํ์ด์ค ์คํ
|
29 |
iface.launch()
|
|
|
1 |
+
from googleapiclient.discovery import build
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
+
# API ํค์ ๊ฒ์ ์์ง ID ์ค์
|
5 |
+
API_KEY = 'AIzaSyDUz3wkGal0ewRtPlzeMit88bV4hS4ZIVY'
|
6 |
+
CSE_ID = '56b34994f47704ddd'
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
+
def multi_search(query):
|
9 |
+
# Google Custom Search JSON API๋ฅผ ์ฌ์ฉํ์ฌ ์น ๊ฒ์
|
10 |
+
service = build("customsearch", "v1", developerKey=API_KEY)
|
11 |
+
web_search_result = service.cse().list(q=query, cx=CSE_ID).execute()
|
12 |
+
web_results = [item['link'] for item in web_search_result.get('items', [])]
|
13 |
|
14 |
+
# YouTube Data API๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋์ค ๊ฒ์
|
15 |
+
youtube = build('youtube', 'v3', developerKey=API_KEY)
|
16 |
+
video_search_result = youtube.search().list(q=query, part='snippet', type='video', maxResults=5).execute()
|
17 |
+
video_results = [f"https://www.youtube.com/watch?v={item['id']['videoId']}" for item in video_search_result.get('items', [])]
|
18 |
|
19 |
+
return web_results, video_results
|
20 |
+
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=multi_search,
|
23 |
+
inputs=gr.Textbox(lines=2, placeholder="๊ฒ์ํ ํ
์คํธ๋ฅผ ์
๋ ฅํ์ธ์..."),
|
24 |
+
outputs=[gr.List(label="์น ๊ฒ์ ๊ฒฐ๊ณผ"), gr.List(label="YouTube ๋น๋์ค ๊ฒ์ ๊ฒฐ๊ณผ")],
|
25 |
+
title="๋ฉํฐ ๊ฒ์ ๊ฒฐ๊ณผ ์ถ๋ ฅ",
|
26 |
+
description="์
๋ ฅ ํ
์คํธ๋ฅผ ๊ธฐ์ค์ผ๋ก ์น ๊ฒ์ ๊ฒฐ๊ณผ์ YouTube ๋น๋์ค ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ๊ตฌ๋ถํ์ฌ ์ถ๋ ฅํฉ๋๋ค."
|
27 |
+
)
|
28 |
|
|
|
29 |
iface.launch()
|