Ofiroz91 commited on
Commit
7e6ae8c
โ€ข
1 Parent(s): 88aa84c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -16
app.py CHANGED
@@ -1,27 +1,24 @@
1
  import gradio as gr
2
- import openai
 
 
 
 
3
 
4
  def summarize_audio(audio_file):
5
- transcript = transcribe_audio(audio_file)
6
- summary = create_summary(transcript)
 
 
7
  return summary
8
 
9
- def transcribe_audio(audio_file):
10
- return "ืชืžืœื•ืœ ืœื“ื•ื’ืžื”"
11
-
12
- def create_summary(transcript):
13
- response = openai.Completion.create(
14
- engine="text-davinci-003",
15
- prompt=f"Please summarize the following text:\n\n{transcript}",
16
- max_tokens=100
17
- )
18
- return response['choices'][0]['text'].strip()
19
-
20
  interface = gr.Interface(
21
  fn=summarize_audio,
22
- inputs=gr.Audio(source="upload", type="file"),
23
  outputs="text",
24
- title="ืžืžื™ืจ ืื•ื“ื™ื• ืœืกื™ื›ื•ื"
 
25
  )
26
 
27
  if __name__ == "__main__":
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # ื™ืฆื™ืจืช pipe ืœืชืžืœื•ืœ ื•ืœืกื™ื›ื•ื
5
+ transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base")
6
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
7
 
8
  def summarize_audio(audio_file):
9
+ # ืชืžืœื•ืœ ื”ืื•ื“ื™ื•
10
+ transcript = transcriber(audio_file)["text"]
11
+ # ื™ืฆื™ืจืช ืกื™ื›ื•ื ืฉืœ ื”ืชืžืœื•ืœ
12
+ summary = summarizer(transcript, max_length=50, min_length=25, do_sample=False)[0]["summary_text"]
13
  return summary
14
 
15
+ # ื”ื’ื“ืจืช ืžืžืฉืง Gradio
 
 
 
 
 
 
 
 
 
 
16
  interface = gr.Interface(
17
  fn=summarize_audio,
18
+ inputs=gr.Audio(source="upload", type="filepath"),
19
  outputs="text",
20
+ title="ืžืžื™ืจ ืื•ื“ื™ื• ืœืกื™ื›ื•ื",
21
+ description="ื”ืขืœื” ืงื•ื‘ืฅ ืื•ื“ื™ื• ืฉืœ ืžืจืฆื” ื•ืงื‘ืœ ืกื™ื›ื•ื ืงืฆืจ ืฉืœ ื”ืชื•ื›ืŸ."
22
  )
23
 
24
  if __name__ == "__main__":