Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import pipeline,
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
# 1.
|
| 6 |
MODEL_ID = "VoltIC/Automated-Text-Summarizer"
|
| 7 |
SUBFOLDER = "summarizer_model"
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
tokenizer =
|
| 12 |
|
| 13 |
-
print("π Phase 2: Loading
|
| 14 |
-
model =
|
| 15 |
|
| 16 |
print("π Phase 3: Building Pipeline...")
|
| 17 |
-
# This defines the 'summarizer' variable globally
|
| 18 |
summarizer = pipeline(
|
| 19 |
"summarization",
|
| 20 |
model=model,
|
| 21 |
tokenizer=tokenizer,
|
| 22 |
framework="pt",
|
| 23 |
-
device=-1
|
| 24 |
)
|
| 25 |
-
print("β
SUCCESS: Summarizer
|
| 26 |
|
| 27 |
-
# 3. Logic
|
| 28 |
def summarize_text(text):
|
| 29 |
-
if not text:
|
| 30 |
-
return "Please enter text."
|
| 31 |
-
|
| 32 |
-
# We use the global 'summarizer' defined above
|
| 33 |
results = summarizer(text, max_length=100, min_length=30, truncation=True)
|
| 34 |
return results[0]['summary_text']
|
| 35 |
|
| 36 |
-
|
| 37 |
-
demo
|
| 38 |
-
fn=summarize_text,
|
| 39 |
-
inputs=gr.Textbox(lines=10, label="Input Text"),
|
| 40 |
-
outputs=gr.Textbox(label="Summary"),
|
| 41 |
-
title="AI Text Summarizer"
|
| 42 |
-
)
|
| 43 |
-
|
| 44 |
-
if __name__ == "__main__":
|
| 45 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import pipeline, BartForConditionalGeneration, BartTokenizer
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# 1. Configuration
|
| 6 |
MODEL_ID = "VoltIC/Automated-Text-Summarizer"
|
| 7 |
SUBFOLDER = "summarizer_model"
|
| 8 |
|
| 9 |
+
print("π Phase 1: Loading BART-specific Tokenizer...")
|
| 10 |
+
# We use BartTokenizer directly to bypass the config.json check
|
| 11 |
+
tokenizer = BartTokenizer.from_pretrained(MODEL_ID, subfolder=SUBFOLDER)
|
| 12 |
|
| 13 |
+
print("π Phase 2: Loading BART Weights...")
|
| 14 |
+
model = BartForConditionalGeneration.from_pretrained(MODEL_ID, subfolder=SUBFOLDER)
|
| 15 |
|
| 16 |
print("π Phase 3: Building Pipeline...")
|
|
|
|
| 17 |
summarizer = pipeline(
|
| 18 |
"summarization",
|
| 19 |
model=model,
|
| 20 |
tokenizer=tokenizer,
|
| 21 |
framework="pt",
|
| 22 |
+
device=-1
|
| 23 |
)
|
| 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(fn=summarize_text, inputs="textbox", outputs="textbox")
|
| 32 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|