Spaces:
Sleeping
Sleeping
File size: 1,531 Bytes
49ea093 03bb178 145ad7d bb2db31 49ea093 03bb178 bb2db31 03bb178 bb2db31 03bb178 bb2db31 49ea093 03bb178 bb2db31 ef26ce8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
from googleapiclient.discovery import build
import gradio as gr
# API ํค์ ๊ฒ์ ์์ง ID ์ค์
API_KEY = 'AIzaSyDUz3wkGal0ewRtPlzeMit88bV4hS4ZIVY'
CSE_ID = '56b34994f47704ddd'
def multi_search(query):
# Google Custom Search JSON API๋ฅผ ์ฌ์ฉํ์ฌ ์น ๊ฒ์
service = build("customsearch", "v1", developerKey=API_KEY)
web_search_result = service.cse().list(q=query, cx=CSE_ID).execute()
web_results = [item['link'] for item in web_search_result.get('items', [])]
# YouTube Data API๋ฅผ ์ฌ์ฉํ์ฌ ๋น๋์ค ๊ฒ์
youtube = build('youtube', 'v3', developerKey=API_KEY)
video_search_result = youtube.search().list(q=query, part='snippet', type='video', maxResults=5).execute()
video_results = [f"https://www.youtube.com/watch?v={item['id']['videoId']}" for item in video_search_result.get('items', [])]
# ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ํํ์ ๋ฆฌ์คํธ๋ก ๋ณํ
web_results_tuples = [(url,) for url in web_results]
video_results_tuples = [(url,) for url in video_results]
return web_results_tuples, video_results_tuples
iface = gr.Interface(
fn=multi_search,
inputs=gr.Textbox(lines=2, placeholder="๊ฒ์ํ ํ
์คํธ๋ฅผ ์
๋ ฅํ์ธ์..."),
outputs=[gr.List(label="์น ๊ฒ์ ๊ฒฐ๊ณผ"), gr.List(label="YouTube ๋น๋์ค ๊ฒ์ ๊ฒฐ๊ณผ")],
title="๋ฉํฐ ๊ฒ์ ๊ฒฐ๊ณผ ์ถ๋ ฅ",
description="์
๋ ฅ ํ
์คํธ๋ฅผ ๊ธฐ์ค์ผ๋ก ์น ๊ฒ์ ๊ฒฐ๊ณผ์ YouTube ๋น๋์ค ๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ๊ตฌ๋ถํ์ฌ ์ถ๋ ฅํฉ๋๋ค."
)
if __name__ == "__main__":
iface.launch() |