Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline,
|
| 3 |
import torch
|
| 4 |
|
| 5 |
# 1. Configuration
|
| 6 |
MODEL_ID = "VoltIC/Automated-Text-Summarizer"
|
| 7 |
SUBFOLDER = "summarizer_model"
|
| 8 |
|
| 9 |
-
print("π Phase 1: Loading
|
| 10 |
-
#
|
| 11 |
-
tokenizer =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
print("π Phase 2: Loading
|
| 14 |
-
model =
|
| 15 |
|
| 16 |
print("π Phase 3: Building Pipeline...")
|
| 17 |
summarizer = pipeline(
|
|
@@ -24,9 +28,17 @@ summarizer = pipeline(
|
|
| 24 |
print("β
SUCCESS: Summarizer Ready!")
|
| 25 |
|
| 26 |
def summarize_text(text):
|
| 27 |
-
if not text: return "Input empty."
|
|
|
|
| 28 |
results = summarizer(text, max_length=100, min_length=30, truncation=True)
|
| 29 |
return results[0]['summary_text']
|
| 30 |
|
| 31 |
-
demo = gr.Interface(
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline, AutoModelForSeq2SeqLM, AutoTokenizer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
# 1. Configuration
|
| 6 |
MODEL_ID = "VoltIC/Automated-Text-Summarizer"
|
| 7 |
SUBFOLDER = "summarizer_model"
|
| 8 |
|
| 9 |
+
print("π Phase 1: Loading Tokenizer...")
|
| 10 |
+
# use_fast=False is the magic fix for the NoneType/vocab_file error
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
| 12 |
+
MODEL_ID,
|
| 13 |
+
subfolder=SUBFOLDER,
|
| 14 |
+
use_fast=False
|
| 15 |
+
)
|
| 16 |
|
| 17 |
+
print("π Phase 2: Loading Model Weights...")
|
| 18 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_ID, subfolder=SUBFOLDER)
|
| 19 |
|
| 20 |
print("π Phase 3: Building Pipeline...")
|
| 21 |
summarizer = pipeline(
|
|
|
|
| 28 |
print("β
SUCCESS: Summarizer Ready!")
|
| 29 |
|
| 30 |
def summarize_text(text):
|
| 31 |
+
if not text: return "Input is empty."
|
| 32 |
+
# Truncation=True ensures we don't exceed the 1024 token limit
|
| 33 |
results = summarizer(text, max_length=100, min_length=30, truncation=True)
|
| 34 |
return results[0]['summary_text']
|
| 35 |
|
| 36 |
+
demo = gr.Interface(
|
| 37 |
+
fn=summarize_text,
|
| 38 |
+
inputs=gr.Textbox(lines=10, placeholder="Paste text here..."),
|
| 39 |
+
outputs="textbox",
|
| 40 |
+
title="AI Text Summarizer"
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
if __name__ == "__main__":
|
| 44 |
+
demo.launch()
|