Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import torch
|
2 |
import gradio as gr
|
3 |
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
4 |
-
import fitz
|
5 |
|
6 |
# Load the model and tokenizer
|
7 |
model_path = 'Sibinraj/T5-finetuned-dialogue_sumxx'
|
@@ -47,7 +47,7 @@ def summarize_text(text, max_length, show_length):
|
|
47 |
summary_ids = model.generate(
|
48 |
inputs,
|
49 |
max_length=max_length + 20, # Allow some buffer
|
50 |
-
min_length=10,
|
51 |
num_beams=5,
|
52 |
no_repeat_ngram_size=2,
|
53 |
early_stopping=True
|
@@ -76,11 +76,13 @@ def summarize_text(text, max_length, show_length):
|
|
76 |
|
77 |
return summary
|
78 |
|
79 |
-
def
|
80 |
"""
|
81 |
-
Handles the
|
82 |
|
83 |
Args:
|
|
|
|
|
84 |
pdf (UploadedFile): The uploaded PDF file.
|
85 |
max_length (int): The maximum length of the summary.
|
86 |
show_length (bool): Whether to show the length of the summary.
|
@@ -88,19 +90,24 @@ def handle_pdf(pdf, max_length, show_length):
|
|
88 |
Returns:
|
89 |
str: The summarized text.
|
90 |
"""
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
93 |
|
94 |
# Define the Gradio interface
|
95 |
interface = gr.Interface(
|
96 |
-
fn=
|
97 |
inputs=[
|
98 |
-
gr.
|
|
|
|
|
99 |
gr.Slider(minimum=10, maximum=150, step=1, label='Max Length'),
|
100 |
gr.Checkbox(label='Show summary length', value=False)
|
101 |
],
|
102 |
outputs=gr.Textbox(label='Summarized Text'),
|
103 |
-
title='PDF
|
104 |
)
|
105 |
|
106 |
# Launch the Gradio interface
|
|
|
1 |
import torch
|
2 |
import gradio as gr
|
3 |
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
4 |
+
import fitz
|
5 |
|
6 |
# Load the model and tokenizer
|
7 |
model_path = 'Sibinraj/T5-finetuned-dialogue_sumxx'
|
|
|
47 |
summary_ids = model.generate(
|
48 |
inputs,
|
49 |
max_length=max_length + 20, # Allow some buffer
|
50 |
+
min_length=10, # Set a reasonable minimum length
|
51 |
num_beams=5,
|
52 |
no_repeat_ngram_size=2,
|
53 |
early_stopping=True
|
|
|
76 |
|
77 |
return summary
|
78 |
|
79 |
+
def handle_input(input_type, text, pdf, max_length, show_length):
|
80 |
"""
|
81 |
+
Handles the user input based on the selected input type.
|
82 |
|
83 |
Args:
|
84 |
+
input_type (str): The type of input (text or PDF).
|
85 |
+
text (str): The text input.
|
86 |
pdf (UploadedFile): The uploaded PDF file.
|
87 |
max_length (int): The maximum length of the summary.
|
88 |
show_length (bool): Whether to show the length of the summary.
|
|
|
90 |
Returns:
|
91 |
str: The summarized text.
|
92 |
"""
|
93 |
+
if input_type == 'Text':
|
94 |
+
return summarize_text(text, max_length, show_length)
|
95 |
+
elif input_type == 'PDF':
|
96 |
+
extracted_text = extract_text_from_pdf(pdf.name)
|
97 |
+
return summarize_text(extracted_text, max_length, show_length)
|
98 |
|
99 |
# Define the Gradio interface
|
100 |
interface = gr.Interface(
|
101 |
+
fn=handle_input,
|
102 |
inputs=[
|
103 |
+
gr.Radio(['Text', 'PDF'], label='Input Type', type='value'),
|
104 |
+
gr.Textbox(lines=10, placeholder='Enter Text Here...', label='Input Text', visible=True),
|
105 |
+
gr.File(label='Upload PDF', type='filepath', visible=True),
|
106 |
gr.Slider(minimum=10, maximum=150, step=1, label='Max Length'),
|
107 |
gr.Checkbox(label='Show summary length', value=False)
|
108 |
],
|
109 |
outputs=gr.Textbox(label='Summarized Text'),
|
110 |
+
title='Text or PDF Summarizer using T5-finetuned-dialogue_sumxx'
|
111 |
)
|
112 |
|
113 |
# Launch the Gradio interface
|