|
|
|
from googleapiclient.discovery import build |
|
import gradio as gr |
|
|
|
|
|
API_KEY = 'AIzaSyDUz3wkGal0ewRtPlzeMit88bV4hS4ZIVY' |
|
CSE_ID = '56b34994f47704ddd' |
|
|
|
def multi_search(query): |
|
|
|
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 = 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() |