mrsk1883 commited on
Commit
c363ecf
1 Parent(s): 62b4fe7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -27
app.py CHANGED
@@ -1,32 +1,28 @@
1
- import gradio as gr
2
- from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
  from PyPDF2 import PdfReader
4
- import os
5
-
6
- model = AutoModelForSeq2SeqLM.from_pretrained("ArtifactAI/led_large_16384_arxiv_summarization")
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
- description = """
21
- Summarize the abstract from a research paper PDF in one sentence.
22
- Works best on papers from ArXiv. Uploaded PDF must contain an abstract section.
23
- """
24
 
25
- examples = ["paper1.pdf", "paper2.pdf"]
 
 
26
 
27
- iface = gr.Interface(fn=summarize, inputs="file", outputs="text",
28
- examples=examples,
29
- title="PDF Abstract Summarizer",
30
- description=description)
 
 
 
 
 
 
31
 
32
- iface.launch(share=True)
 
 
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()