springwater
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
-
from youtubesearchpython import VideosSearch, Transcript
|
2 |
import gradio as gr
|
3 |
import openai
|
4 |
import os
|
5 |
import requests
|
6 |
|
7 |
-
# openai.api_key = os.getenv('O_API_KEY')
|
8 |
|
9 |
def search_youtube_videos(keyword):
|
10 |
videos_search = VideosSearch(keyword, limit=5)
|
@@ -25,7 +24,7 @@ def get_transcript(urls):
|
|
25 |
def summarize_text(contents, OPENAI_API_KEY):
|
26 |
API_URL = "https://api.openai.com/v1/chat/completions"
|
27 |
payload = {
|
28 |
-
"model": "gpt-4-0125-preview",
|
29 |
"messages": [{
|
30 |
"role": "system",
|
31 |
"content": "λΉμ μ λ΄μ©μ μμ½νλ μ±λ΄μ
λλ€."
|
@@ -46,39 +45,6 @@ def summarize_text(contents, OPENAI_API_KEY):
|
|
46 |
# μ€λ₯ λ©μμ§ κ°μ
|
47 |
return f"μ€λ₯κ° λ°μνμ΅λλ€. μν μ½λ: {response.status_code}, λ©μμ§: {response.json().get('error', {}).get('message', 'Unknown error')}", ""
|
48 |
|
49 |
-
|
50 |
-
# def summarize_text(contents, OPENAI_API_KEY):
|
51 |
-
|
52 |
-
# response = openai.ChatCompletion.create(
|
53 |
-
|
54 |
-
# model="gpt-4-turbo-preview",
|
55 |
-
# messages=[
|
56 |
-
# {"role": "system", "content": "You are a helpful assistant."},
|
57 |
-
# {"role": "user", "content": f"Summarize this: {contents}"}
|
58 |
-
# ],
|
59 |
-
# headers={
|
60 |
-
# "Content-Type": "application/json",
|
61 |
-
# "Authorization": f"Bearer {OPENAI_API_KEY}"
|
62 |
-
# }
|
63 |
-
# )
|
64 |
-
# return response.choices[0].message['content'].strip()
|
65 |
-
|
66 |
-
# def summarize_text(contents):
|
67 |
-
# response = openai.ChatCompletion.create(
|
68 |
-
# engine="gpt-3.5-turbo",
|
69 |
-
# prompt=f"μμ½: {contents}",
|
70 |
-
# max_tokens=150
|
71 |
-
# )
|
72 |
-
# return response.choices[0].text.strip()
|
73 |
-
|
74 |
-
# Function to integrate all the functionalities
|
75 |
-
|
76 |
-
# def summarize_youtube_videos(keyword, OPENAI_API_KEY):
|
77 |
-
# urls = search_youtube_videos(keyword)
|
78 |
-
# contents = get_transcript(urls)
|
79 |
-
# summary, _ = summarize_text(contents,OPENAI_API_KEY)
|
80 |
-
# return summary,""
|
81 |
-
|
82 |
def summarize_youtube_videos(keyword, OPENAI_API_KEY):
|
83 |
urls = search_youtube_videos(keyword)
|
84 |
contents = get_transcript(urls)
|
@@ -88,7 +54,7 @@ def summarize_youtube_videos(keyword, OPENAI_API_KEY):
|
|
88 |
|
89 |
with gr.Blocks(css="footer {visibility: hidden;}") as demo:
|
90 |
|
91 |
-
with gr.Tab():
|
92 |
keyword = gr.Textbox(label="keyword", placeholder='ν€μλλ₯Ό μ
λ ₯νμΈμ. (μ.λΉνΈμ½μΈ)')
|
93 |
OPENAI_API_KEY = gr.Textbox(label="OpenAI API ν€", placeholder="OpenAI API ν€λ₯Ό μ
λ ₯νμΈμ")
|
94 |
analysis_result = gr.HTML()
|
|
|
1 |
+
from youtubesearchpython import VideosSearch, Transcript
|
2 |
import gradio as gr
|
3 |
import openai
|
4 |
import os
|
5 |
import requests
|
6 |
|
|
|
7 |
|
8 |
def search_youtube_videos(keyword):
|
9 |
videos_search = VideosSearch(keyword, limit=5)
|
|
|
24 |
def summarize_text(contents, OPENAI_API_KEY):
|
25 |
API_URL = "https://api.openai.com/v1/chat/completions"
|
26 |
payload = {
|
27 |
+
"model": "gpt-4-0125-preview",
|
28 |
"messages": [{
|
29 |
"role": "system",
|
30 |
"content": "λΉμ μ λ΄μ©μ μμ½νλ μ±λ΄μ
λλ€."
|
|
|
45 |
# μ€λ₯ λ©μμ§ κ°μ
|
46 |
return f"μ€λ₯κ° λ°μνμ΅λλ€. μν μ½λ: {response.status_code}, λ©μμ§: {response.json().get('error', {}).get('message', 'Unknown error')}", ""
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
def summarize_youtube_videos(keyword, OPENAI_API_KEY):
|
49 |
urls = search_youtube_videos(keyword)
|
50 |
contents = get_transcript(urls)
|
|
|
54 |
|
55 |
with gr.Blocks(css="footer {visibility: hidden;}") as demo:
|
56 |
|
57 |
+
with gr.Tab("youtube"):
|
58 |
keyword = gr.Textbox(label="keyword", placeholder='ν€μλλ₯Ό μ
λ ₯νμΈμ. (μ.λΉνΈμ½μΈ)')
|
59 |
OPENAI_API_KEY = gr.Textbox(label="OpenAI API ν€", placeholder="OpenAI API ν€λ₯Ό μ
λ ₯νμΈμ")
|
60 |
analysis_result = gr.HTML()
|