File size: 1,192 Bytes
0d3ec20
6245545
 
0d3ec20
 
 
 
 
6245545
0d3ec20
6245545
 
0d3ec20
6245545
 
 
 
 
 
 
 
 
0d3ec20
 
 
6245545
 
0d3ec20
6245545
0d3ec20
 
 
 
 
6245545
 
5b8f3bd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gradio as gr
from PyPDF2 import PdfReader
from transformers import pipeline
from bark import SAMPLE_RATE, generate_audio, preload_models
from IPython.display import Audio

# Preload Bark models
preload_models()

def summarize_generate_audio(files):
    summarizer = pipeline("summarization", model="stevhliu/my_awesome_billsum_model")
    summaries = []
    audios = []

    for file in files:
        with open(file.name, "rb") as pdf_file:
            pdf_reader = PdfReader(pdf_file)
            text = ""
            for page in pdf_reader.pages:
                text += page.extract_text() + "\n"
            summary = summarizer(text, max_length=50, min_length=10, do_sample=False)[0]['summary_text']
            summaries.append(summary)
            audio_array = generate_audio(summary)
            audios.append(audio_array)
    return summaries, audios

iface = gr.Interface(
    fn=summarize_generate_audio,
    inputs=gr.UploadButton("Click to Upload a PDF", file_types=["pdf"], file_count="multiple"),
    outputs=[
        gr.Textbox(label="Summarized Text"),
        gr.Audio(label="Generated Audio")
    ],
    title="PDF Summarizer & Audio Generator"
)

iface.launch()