plainly / app.py
mynti's picture
updated plainly title to plainlyy title
0d49f4c
import torch
from transformers import T5Tokenizer, T5ForConditionalGeneration
import gradio as gr
def simplify(text):
model= T5ForConditionalGeneration.from_pretrained("mynti/plainly-v1")
tokenizer = T5Tokenizer.from_pretrained('t5-base', model_max_length=512)
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
model = model.to(device)
preprocess_text = "simplify: " + text.strip()
tokenized_text = tokenizer.encode(preprocess_text, return_tensors="pt").to(device)
summary_ids = model.generate(
tokenized_text,
max_length=512,
num_beams=2,
repetition_penalty=2.0,
length_penalty=0.5,
early_stopping=True
)
output = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
return output
interface = gr.Interface(
fn=simplify,
inputs=gr.inputs.Textbox(lines=5, placeholder="Enter a sentence here..", label="Normal English"),
outputs=gr.inputs.Textbox(lines=5, label="Simple English"),
cache_examples=True,
title="Plainlyy",
description="Translates any english sentence into a simpler and easier to understand version of it.",
allow_flagging="never",
examples=[
"In Brazilian cities, white workers earn roughly twice as much as those of African descent.",
"The other group did a ten-minute warm-up on the bike, followed by four minutes of Tabata intervals, four times a week plus one 30-minute session of steady exercise with two minutes of intervals.",
"The number of minutes Americans spend on Facebook appears to be falling, too.",
"Nearly 80% of young smartphone owners regularly use a social networking application, says the research firm Enders Analysis, but two-thirds use more than one.",
"The growing of coca leaves is legal and licensed 12 in Bolivia."
]
)
interface.launch()