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