Brass-monkey commited on
Commit
0d3ec20
1 Parent(s): 5b8f3bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -1,10 +1,16 @@
 
1
  from PyPDF2 import PdfReader
2
  from transformers import pipeline
3
- import gradio as gr
 
 
 
 
4
 
5
- def summarize_pdf_content(files):
6
  summarizer = pipeline("summarization", model="stevhliu/my_awesome_billsum_model")
7
  summaries = []
 
8
 
9
  for file in files:
10
  with open(file.name, "rb") as pdf_file:
@@ -14,13 +20,18 @@ def summarize_pdf_content(files):
14
  text += page.extract_text() + "\n"
15
  summary = summarizer(text, max_length=50, min_length=10, do_sample=False)[0]['summary_text']
16
  summaries.append(summary)
17
- return summaries
 
 
18
 
19
  iface = gr.Interface(
20
- fn=summarize_pdf_content,
21
  inputs=gr.UploadButton("Click to Upload a PDF", file_types=["pdf"], file_count="multiple"),
22
- outputs=gr.Textbox(label="Summarized Text"),
23
- title="PDF Summarizer"
 
 
 
24
  )
25
 
26
  iface.launch()
 
1
+ import gradio as gr
2
  from PyPDF2 import PdfReader
3
  from transformers import pipeline
4
+ from bark import SAMPLE_RATE, generate_audio, preload_models
5
+ from IPython.display import Audio
6
+
7
+ # Preload Bark models
8
+ preload_models()
9
 
10
+ def summarize_generate_audio(files):
11
  summarizer = pipeline("summarization", model="stevhliu/my_awesome_billsum_model")
12
  summaries = []
13
+ audios = []
14
 
15
  for file in files:
16
  with open(file.name, "rb") as pdf_file:
 
20
  text += page.extract_text() + "\n"
21
  summary = summarizer(text, max_length=50, min_length=10, do_sample=False)[0]['summary_text']
22
  summaries.append(summary)
23
+ audio_array = generate_audio(summary)
24
+ audios.append(audio_array)
25
+ return summaries, audios
26
 
27
  iface = gr.Interface(
28
+ fn=summarize_generate_audio,
29
  inputs=gr.UploadButton("Click to Upload a PDF", file_types=["pdf"], file_count="multiple"),
30
+ outputs=[
31
+ gr.Textbox(label="Summarized Text"),
32
+ gr.Audio(label="Generated Audio")
33
+ ],
34
+ title="PDF Summarizer & Audio Generator"
35
  )
36
 
37
  iface.launch()