parrot2 / app.py
Mollymo's picture
Update app.py
e747a1e verified
Raw
History Blame Contribute Delete
930 Bytes
import gradio as gr
from transformers import pipeline
import torch
# Lightweight fallback model
def load_model():
try:
return pipeline("text2text-generation",
model="prithivida/parrot_paraphraser_on_T5",
device="cuda" if torch.cuda.is_available() else "cpu")
except:
return None
parrot_pipeline = load_model()
def paraphrase_text(text):
if not text.strip():
return "⚠️ Please enter text"
if parrot_pipeline is None:
return "❌ Model unavailable. Try again later."
try:
outputs = parrot_pipeline(
text,
num_return_sequences=3,
num_beams=5,
max_length=128
)
return "\n\n".join([f"{i+1}. {res['generated_text']}"
for i, res in enumerate(outputs)])
except Exception as e:
return f"⚠️ Error: {str(e)}"