added gradio interface
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import T5Tokenizer, T5ForConditionalGeneration
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
|
6 |
+
def simplify(text):
|
7 |
+
model= T5ForConditionalGeneration.from_pretrained("mynti/plainly-v1")
|
8 |
+
tokenizer = T5Tokenizer.from_pretrained('t5-base')
|
9 |
+
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
|
10 |
+
model = model.to(device)
|
11 |
+
preprocess_text = "simplify: " + text.strip()
|
12 |
+
tokenized_text = tokenizer.encode(preprocess_text, return_tensors="pt").to(device)
|
13 |
+
|
14 |
+
summary_ids = model.generate(
|
15 |
+
tokenized_text,
|
16 |
+
max_length=512,
|
17 |
+
num_beams=2,
|
18 |
+
repetition_penalty=2.0,
|
19 |
+
length_penalty=0.5,
|
20 |
+
early_stopping=True
|
21 |
+
)
|
22 |
+
|
23 |
+
output = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
24 |
+
return output
|
25 |
+
|
26 |
+
|
27 |
+
interface = gr.Interface(
|
28 |
+
fn=simplify,
|
29 |
+
inputs=gr.inputs.Textbox(lines=5, placeholder="Enter a sentence here..", label="Normal English"),
|
30 |
+
outputs=gr.inputs.Textbox(lines=5, label="Simple English"),
|
31 |
+
cache_examples=True,
|
32 |
+
title="Plainly",
|
33 |
+
description="Translates any english sentence into a simpler and easier to understand version of it.",
|
34 |
+
allow_flagging="never",
|
35 |
+
examples=[
|
36 |
+
"In Brazilian cities, white workers earn roughly twice as much as those of African descent.",
|
37 |
+
"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.",
|
38 |
+
"The number of minutes Americans spend on Facebook appears to be falling, too.",
|
39 |
+
"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.",
|
40 |
+
"The growing of coca leaves is legal and licensed 12 in Bolivia."
|
41 |
+
]
|
42 |
+
)
|
43 |
+
interface.launch()
|
44 |
+
|