File size: 1,313 Bytes
03bb178
145ad7d
bb2db31
03bb178
 
 
bb2db31
03bb178
 
 
 
 
bb2db31
03bb178
 
 
 
bb2db31
03bb178
 
 
 
 
 
 
 
 
bb2db31
 
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
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', [])]

    return web_results, video_results

iface = gr.Interface(
    fn=multi_search,
    inputs=gr.Textbox(lines=2, placeholder="검색할 텍스트를 입력하세요..."),
    outputs=[gr.List(label="웹 검색 결과"), gr.List(label="YouTube 비디오 검색 결과")],
    title="멀티 검색 결과 출력",
    description="입력 텍스트를 기준으로 웹 검색 결과와 YouTube 비디오 검색 결과를 구분하여 출력합니다."
)

iface.launch()