Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,28 @@
|
|
1 |
-
|
2 |
-
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
from PyPDF2 import PdfReader
|
4 |
-
import
|
5 |
-
|
6 |
-
|
7 |
-
tokenizer = AutoTokenizer.from_pretrained("ArtifactAI/led_large_16384_arxiv_summarization")
|
8 |
-
|
9 |
-
def summarize(pdf):
|
10 |
-
reader = PdfReader(pdf.name)
|
11 |
-
page = next(reader.pages)
|
12 |
-
text = page.extract_text()
|
13 |
-
|
14 |
-
inputs = tokenizer(text, return_tensors="pt")
|
15 |
-
outputs = model.generate(**inputs)
|
16 |
-
|
17 |
-
summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
18 |
-
return summary
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
|
|
|
1 |
+
# app/main.py
|
|
|
2 |
from PyPDF2 import PdfReader
|
3 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
4 |
+
from gtts import gTTS
|
5 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
# Load the pre-trained model and tokenizer
|
8 |
+
model_name = "ArtifactAI/led_large_16384_arxiv_summarization"
|
9 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
|
12 |
+
def summarize_pdf_abstract(pdf_path):
|
13 |
+
# Implement the function to summarize PDF abstracts (similar to your previous code)
|
14 |
+
# ...
|
15 |
|
16 |
+
# Gradio Interface
|
17 |
+
iface = gr.Interface(
|
18 |
+
fn=summarize_pdf_abstract,
|
19 |
+
inputs=gr.File(type="file", label="Upload a PDF file"),
|
20 |
+
outputs="text",
|
21 |
+
live=True,
|
22 |
+
interpretation="default",
|
23 |
+
title="PDF Abstract Summarizer",
|
24 |
+
description="This app accepts PDFs with abstracts and generates a summary.",
|
25 |
+
)
|
26 |
|
27 |
+
# Launch the Gradio interface
|
28 |
+
iface.launch()
|