File size: 1,980 Bytes
d32553f
 
 
 
 
 
 
f8cb6da
d32553f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d49f4c
d32553f
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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()