Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,25 +13,17 @@ def extract_text_from_pdf(pdf_content):
|
|
| 13 |
|
| 14 |
|
| 15 |
def generate_summary(file_content, user_input_text):
|
| 16 |
-
# Handle uploaded file
|
| 17 |
if file_content:
|
| 18 |
if isinstance(file_content, bytes):
|
| 19 |
-
# Handle PDF file
|
| 20 |
input_text = extract_text_from_pdf(file_content)
|
| 21 |
else:
|
| 22 |
-
# Handle uploaded text file
|
| 23 |
input_text = file_content.read().decode("utf-8")
|
| 24 |
else:
|
| 25 |
-
# Handle user input text
|
| 26 |
input_text = user_input_text
|
| 27 |
-
|
| 28 |
-
# Load pre-trained Flan-T5 model
|
| 29 |
text_generator = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 30 |
|
| 31 |
-
# Generate summary
|
| 32 |
summary = text_generator(input_text, max_length=1024, num_beams=4)
|
| 33 |
|
| 34 |
-
# Return results
|
| 35 |
return {
|
| 36 |
"Extracted Information": input_text,
|
| 37 |
"Book Summary": summary[0]["generated_text"],
|
|
@@ -43,9 +35,9 @@ iface = gr.Interface(
|
|
| 43 |
fn=generate_summary,
|
| 44 |
inputs=[gr.File(label="Upload File"), gr.Textbox(label="Enter Text")],
|
| 45 |
outputs=[
|
| 46 |
-
gr.Textbox(),
|
| 47 |
-
gr.Textbox(),
|
| 48 |
-
gr.Textbox(),
|
| 49 |
],
|
| 50 |
live=True,
|
| 51 |
)
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
def generate_summary(file_content, user_input_text):
|
|
|
|
| 16 |
if file_content:
|
| 17 |
if isinstance(file_content, bytes):
|
|
|
|
| 18 |
input_text = extract_text_from_pdf(file_content)
|
| 19 |
else:
|
|
|
|
| 20 |
input_text = file_content.read().decode("utf-8")
|
| 21 |
else:
|
|
|
|
| 22 |
input_text = user_input_text
|
|
|
|
|
|
|
| 23 |
text_generator = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 24 |
|
|
|
|
| 25 |
summary = text_generator(input_text, max_length=1024, num_beams=4)
|
| 26 |
|
|
|
|
| 27 |
return {
|
| 28 |
"Extracted Information": input_text,
|
| 29 |
"Book Summary": summary[0]["generated_text"],
|
|
|
|
| 35 |
fn=generate_summary,
|
| 36 |
inputs=[gr.File(label="Upload File"), gr.Textbox(label="Enter Text")],
|
| 37 |
outputs=[
|
| 38 |
+
gr.Textbox(label="Extracted Information"),
|
| 39 |
+
gr.Textbox(label="Book Summary"),
|
| 40 |
+
gr.Textbox(label="Rewiew"),
|
| 41 |
],
|
| 42 |
live=True,
|
| 43 |
)
|