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