File size: 3,145 Bytes
2819be2
465c02f
2819be2
465c02f
ad28e9f
8626295
2819be2
4261a30
8626295
2819be2
 
 
8626295
 
 
d8caea7
 
 
 
 
 
 
 
 
 
 
 
2819be2
d8caea7
 
 
 
 
 
 
 
 
2819be2
d8caea7
 
 
 
 
 
 
8626295
d8caea7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8626295
d8caea7
2819be2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from youtubesearchpython import VideosSearch
import gradio as gr
import openai
from langchain_community.document_loaders import YoutubeLoader
import os

# OpenAI API ν‚€ μ„€μ •
openai.api_key = os.getenv('O_API_KEY')

def search_youtube_videos(keyword, limit=5, order='date'):
    videos_search = VideosSearch(keyword, limit=limit, order=order)
    results = videos_search.result()
    video_urls = [video['link'] for video in results['result']]
    return video_urls

# Gradio μΈν„°νŽ˜μ΄μŠ€ μ„€μ •
interface = gr.Interface(
    fn=search_youtube_videos,
    inputs=[
        gr.Textbox(label="검색 ν‚€μ›Œλ“œ", placeholder="YouTubeμ—μ„œ 검색할 ν‚€μ›Œλ“œλ₯Ό μž…λ ₯ν•˜μ„Έμš”."),
        gr.Slider(minimum=1, maximum=10, default=5, label="검색 κ²°κ³Ό 개수"),
        gr.Radio(choices=['date', 'relevance', 'rating', 'title', 'viewCount'], label="μ •λ ¬ μˆœμ„œ", default='date')
    ],
    outputs=gr.Textbox(label="검색 κ²°κ³Ό"),
    title="YouTube λΉ„λ””μ˜€ 검색",
    description="YouTubeμ—μ„œ λΉ„λ””μ˜€λ₯Ό κ²€μƒ‰ν•˜κ³  결과의 링크λ₯Ό λ°›μ•„λ³΄μ„Έμš”."
)

# Gradio μ•± μ‹€ν–‰
if __name__ == "__main__":
    interface.launch()
    
# def get_transcript(url):
#     loader = YoutubeLoader()
#     transcript = loader.load(url)
#     text = " ".join([segment['text'] for segment in transcript['segments']])
#     return text

# def summarize_text(text):
#     response = openai.Completion.create(
#         engine="text-davinci-003",
#         prompt=f"μš”μ•½: {text}",
#         max_tokens=150
#     )
#     return response.choices[0].text.strip()

# def process_keyword(keyword):
#     video_urls = search_youtube_videos(keyword)
#     summaries = []
#     for url in video_urls:
#         try:
#             text = get_transcript(url)
#             summary = summarize_text(text)
#             summaries.append(f"URL: {url}\nSummary: {summary}\n")
#         except Exception as e:
#             summaries.append(f"URL: {url}\nError: {str(e)}\n")
#     return "\n".join(summaries)

# # Gradio μΈν„°νŽ˜μ΄μŠ€
# interface = gr.Interface(
#     fn=process_keyword,
#     inputs=gr.Textbox(label="검색 ν‚€μ›Œλ“œ"),
#     outputs=gr.Textbox(label="κ²°κ³Ό"),
# )

# interface.launch()


# from youtubesearchpython import VideosSearch
# from langchain_community.document_loaders import YoutubeLoader
# import gradio as gr

# def search_youtube_videos(keyword, limit=5, order='date'):
#     videos_search = VideosSearch(keyword, limit=limit, order='date')
#     results = videos_search.result()

#     video_urls = [video['link'] for video in results['result']]
#     return video_urls

# def gradio_interface(keyword):
#     video_urls = search_youtube_videos(keyword)
#     return "\n".join(video_urls)

# interface = gr.Interface(
#     fn=gradio_interface,
#     inputs=gr.Textbox(label="검색 ν‚€μ›Œλ“œλ₯Ό μž…λ ₯ν•˜μ„Έμš”"),
#     outputs=gr.Textbox(label="κ²€μƒ‰λœ 유튜브 λ™μ˜μƒ URL"),
#     title="유튜브 검색 λ„μš°λ―Έ",
#     description="ν‚€μ›Œλ“œλ₯Ό μž…λ ₯ν•˜λ©΄ μœ νŠœλΈŒμ—μ„œ ν•΄λ‹Ή ν‚€μ›Œλ“œλ‘œ κ²€μƒ‰ν•œ ν›„ λ™μ˜μƒ URL을 λ³΄μ—¬μ€λ‹ˆλ‹€."
# )

# if __name__ == "__main__":
#     interface.launch()