Spaces:
Sleeping
Sleeping
| from transformers import AutoTokenizer, AutoModelForSeq2SeqLM | |
| import gradio as gr | |
| import torch | |
| # Load model manually (bypasses pipeline issue) | |
| model_name = "t5-small" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForSeq2SeqLM.from_pretrained(model_name) | |
| def summarize_text(text): | |
| if not text.strip(): | |
| return "Please enter some text." | |
| input_text = "summarize: " + text | |
| inputs = tokenizer( | |
| input_text, | |
| return_tensors="pt", | |
| max_length=512, | |
| truncation=True | |
| ) | |
| summary_ids = model.generate( | |
| inputs["input_ids"], | |
| max_length=120, | |
| min_length=30, | |
| length_penalty=2.0, | |
| num_beams=4, | |
| early_stopping=True | |
| ) | |
| summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True) | |
| return summary | |
| demo = gr.Interface( | |
| fn=summarize_text, | |
| inputs=gr.Textbox(lines=10, placeholder="Enter long text here..."), | |
| outputs="text", | |
| title="📝 T5 Text Summarizer", | |
| description="Summarize long text using T5 (manual model loading)" | |
| ) | |
| demo.launch() |