Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline
|
| 3 |
-
import torch
|
| 4 |
|
|
|
|
| 5 |
MODEL_ID = "VoltIC/Automated-Text-Summarizer"
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
# Load the model with low_cpu_mem_usage to save RAM
|
| 8 |
-
print("π Initializing model...")
|
| 9 |
try:
|
|
|
|
|
|
|
|
|
|
| 10 |
summarizer = pipeline(
|
| 11 |
"summarization",
|
| 12 |
-
model=
|
| 13 |
-
|
| 14 |
-
framework="pt"
|
| 15 |
-
device=-1 # Explicitly force CPU
|
| 16 |
)
|
| 17 |
print("β
System Ready")
|
| 18 |
except Exception as e:
|
|
@@ -23,25 +26,23 @@ def summarize_text(text):
|
|
| 23 |
return "Error: Text is too short."
|
| 24 |
|
| 25 |
try:
|
| 26 |
-
# TRUNCATION is the key.
|
| 27 |
-
# It prevents the model from trying to process 10,000 words at once.
|
| 28 |
result = summarizer(
|
| 29 |
text,
|
| 30 |
max_length=100,
|
| 31 |
min_length=30,
|
| 32 |
do_sample=False,
|
| 33 |
-
truncation=True
|
| 34 |
)
|
| 35 |
return result[0]['summary_text']
|
| 36 |
except Exception as e:
|
| 37 |
return f"Runtime Error: {str(e)}"
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
gr.
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
btn.click(fn=summarize_text, inputs=input_box, outputs=output_box)
|
| 47 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
|
|
|
|
| 3 |
|
| 4 |
+
# 1. Configuration
|
| 5 |
MODEL_ID = "VoltIC/Automated-Text-Summarizer"
|
| 6 |
+
SUBFOLDER = "summarizer_model"
|
| 7 |
+
|
| 8 |
+
print("π Loading model and tokenizer...")
|
| 9 |
|
|
|
|
|
|
|
| 10 |
try:
|
| 11 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID, subfolder=SUBFOLDER)
|
| 12 |
+
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, subfolder=SUBFOLDER)
|
| 13 |
+
|
| 14 |
summarizer = pipeline(
|
| 15 |
"summarization",
|
| 16 |
+
model=model,
|
| 17 |
+
tokenizer=tokenizer,
|
| 18 |
+
framework="pt"
|
|
|
|
| 19 |
)
|
| 20 |
print("β
System Ready")
|
| 21 |
except Exception as e:
|
|
|
|
| 26 |
return "Error: Text is too short."
|
| 27 |
|
| 28 |
try:
|
|
|
|
|
|
|
| 29 |
result = summarizer(
|
| 30 |
text,
|
| 31 |
max_length=100,
|
| 32 |
min_length=30,
|
| 33 |
do_sample=False,
|
| 34 |
+
truncation=True
|
| 35 |
)
|
| 36 |
return result[0]['summary_text']
|
| 37 |
except Exception as e:
|
| 38 |
return f"Runtime Error: {str(e)}"
|
| 39 |
|
| 40 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 41 |
+
gr.Markdown("# π AI Text Summarizer")
|
| 42 |
+
with gr.Column():
|
| 43 |
+
input_box = gr.Textbox(label="Input Text", lines=8)
|
| 44 |
+
output_box = gr.Textbox(label="Summary Result", lines=4)
|
| 45 |
+
btn = gr.Button("Summarize", variant="primary")
|
| 46 |
|
| 47 |
btn.click(fn=summarize_text, inputs=input_box, outputs=output_box)
|
| 48 |
|