Brass-monkey commited on
Commit
3fcefd6
1 Parent(s): 0d3ec20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -18
app.py CHANGED
@@ -1,37 +1,27 @@
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:
17
  pdf_reader = PdfReader(pdf_file)
18
  text = ""
19
  for page in pdf_reader.pages:
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()
 
1
  import gradio as gr
2
  from PyPDF2 import PdfReader
3
  from transformers import pipeline
 
 
4
 
5
+ def summarize_and_extract_text(files):
6
+ summarizer = pipeline("summarization")
 
 
 
7
  summaries = []
8
+ extracted_texts = []
 
9
  for file in files:
10
  with open(file.name, "rb") as pdf_file:
11
  pdf_reader = PdfReader(pdf_file)
12
  text = ""
13
  for page in pdf_reader.pages:
14
  text += page.extract_text() + "\n"
15
+ extracted_texts.append(text)
16
  summary = summarizer(text, max_length=50, min_length=10, do_sample=False)[0]['summary_text']
17
  summaries.append(summary)
18
+ return summaries, extracted_texts
 
 
19
 
20
  iface = gr.Interface(
21
+ fn=summarize_and_extract_text,
22
  inputs=gr.UploadButton("Click to Upload a PDF", file_types=["pdf"], file_count="multiple"),
23
+ outputs=[gr.Textbox(label="Summarized Text"), gr.Textbox(label="Extracted Text")],
24
+ title="PDF Summarizer & Extracted Text"
 
 
 
25
  )
26
 
27
  iface.launch()