springwater commited on
Commit
7fb6aae
β€’
1 Parent(s): 6000f8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -37
app.py CHANGED
@@ -1,10 +1,9 @@
1
- from youtubesearchpython import VideosSearch, Transcript # Changed import statement
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()