hadxu commited on
Commit
5ee7f09
·
1 Parent(s): cd864c2

add summary

Browse files
Files changed (2) hide show
  1. app.py +36 -11
  2. requirements.txt +2 -1
app.py CHANGED
@@ -2,13 +2,12 @@ import gradio as gr
2
  import yt_dlp
3
  import os
4
  from openai import OpenAI
 
5
 
6
- client = OpenAI(api_key=os.environ['OPENAI_API_KEY'])
7
-
8
- # from faster_whisper import WhisperModel
9
- # tiny, tiny.en, base, base.en, small, small.en, medium, medium.en, large-v1, large-v2, large-v3, or large
10
- # model_name = 'base'
11
- # model = WhisperModel(model_name, device="cpu", download_root="./models")
12
 
13
  ydl_opts = {
14
  'outtmpl': 'demo.m4a',
@@ -27,6 +26,7 @@ def download_audio(url):
27
  code = ydl.download([url])
28
  assert code == 0, "Failed to download audio"
29
 
 
30
  def generate_text(url):
31
  download_audio(url)
32
  with open("demo.m4a", "rb") as f:
@@ -35,20 +35,45 @@ def generate_text(url):
35
  file=f,
36
  response_format="text"
37
  )
38
- return transcription.text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
  with gr.Blocks() as demo:
41
  with gr.Column():
42
  name = gr.Textbox(label="Enter your youtube url")
43
- button = gr.Button("Download")
44
 
45
- with gr.Column():
46
- output = gr.TextArea(label="Output")
47
 
48
- button.click(
 
 
 
 
49
  generate_text,
50
  inputs=[name],
51
  outputs=[output],
52
  )
53
 
 
 
 
 
 
 
54
  demo.launch()
 
2
  import yt_dlp
3
  import os
4
  from openai import OpenAI
5
+ import anthropic
6
 
7
+ client = OpenAI(
8
+ api_key=os.getenv("OPENAI_API_KEY"),
9
+ )
10
+ claude_client = anthropic.Anthropic()
 
 
11
 
12
  ydl_opts = {
13
  'outtmpl': 'demo.m4a',
 
26
  code = ydl.download([url])
27
  assert code == 0, "Failed to download audio"
28
 
29
+ text = ""
30
  def generate_text(url):
31
  download_audio(url)
32
  with open("demo.m4a", "rb") as f:
 
35
  file=f,
36
  response_format="text"
37
  )
38
+ global text
39
+ text = transcription.text
40
+
41
+ def summarize_text():
42
+ print(text)
43
+ prompt = f"Please summarize the following article in 5 sentences or less: [{text}]"
44
+ message = claude_client.messages.create(
45
+ model="claude-3-haiku-20240307",
46
+ max_tokens=1000,
47
+ temperature=0.0,
48
+ # system="Respond only in mandarin",
49
+ messages=[
50
+ {"role": "user", "content": prompt}
51
+ ]
52
+ )
53
+ return message.content[0].text
54
 
55
  with gr.Blocks() as demo:
56
  with gr.Column():
57
  name = gr.Textbox(label="Enter your youtube url")
58
+ button_download = gr.Button("Download")
59
 
60
+ with gr.Row():
61
+ output = gr.TextArea(label="Output")
62
 
63
+ with gr.Column():
64
+ button_summary = gr.Button("Summary")
65
+ summary = gr.TextArea(label="Summary")
66
+
67
+ button_download.click(
68
  generate_text,
69
  inputs=[name],
70
  outputs=[output],
71
  )
72
 
73
+ button_summary.click(
74
+ summarize_text,
75
+ inputs=[],
76
+ outputs=[summary],
77
+ )
78
+
79
  demo.launch()
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  yt-dlp
2
- faster-whisper
 
 
1
  yt-dlp
2
+ openai
3
+ anthropic