Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,40 @@
|
|
| 1 |
import fitz
|
| 2 |
-
from transformers import
|
| 3 |
-
import gradio as gr
|
| 4 |
|
| 5 |
def extract_text_from_pdf(pdf_path):
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def generate_review(summary):
|
| 14 |
-
# Your custom logic to generate a review
|
| 15 |
-
review = "The book conveys a powerful message about..."
|
| 16 |
-
return review
|
| 17 |
|
| 18 |
def generate_summary(pdf_path):
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
model = GPT2Model.from_pretrained('gpt2')
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
summary = model.generate(input_tokens)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
|
| 37 |
iface = gr.Interface(
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
)
|
| 47 |
|
| 48 |
iface.launch()
|
|
|
|
| 1 |
import fitz
|
| 2 |
+
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
def extract_text_from_pdf(pdf_path):
|
| 5 |
+
doc = fitz.open(pdf_path)
|
| 6 |
+
text = ""
|
| 7 |
+
for page_num in range(doc.page_count):
|
| 8 |
+
page = doc[page_num]
|
| 9 |
+
text += page.get_text()
|
| 10 |
+
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def generate_summary(pdf_path):
|
| 13 |
+
# Load pre-trained Flan-T5 model
|
| 14 |
+
text_generator = pipeline("text2text-generation", model="google/flan-t5-base")
|
|
|
|
| 15 |
|
| 16 |
+
# Extract text from the PDF
|
| 17 |
+
input_text = extract_text_from_pdf(pdf_path)
|
| 18 |
|
| 19 |
+
# Generate summary
|
| 20 |
+
summary = text_generator(input_text, max_length=1024, num_beams=4)
|
|
|
|
| 21 |
|
| 22 |
+
# Return results
|
| 23 |
+
return {
|
| 24 |
+
"Extracted Information": input_text,
|
| 25 |
+
"Book Summary": summary[0]["generated_text"],
|
| 26 |
+
"Review": "The book conveys a powerful message about..."
|
| 27 |
+
}
|
| 28 |
|
| 29 |
iface = gr.Interface(
|
| 30 |
+
fn=generate_summary,
|
| 31 |
+
inputs=gr.File(),
|
| 32 |
+
outputs=[
|
| 33 |
+
gr.Textbox(),
|
| 34 |
+
gr.Textbox(),
|
| 35 |
+
gr.Textbox(),
|
| 36 |
+
],
|
| 37 |
+
live=True
|
| 38 |
)
|
| 39 |
|
| 40 |
iface.launch()
|