Spaces:
Runtime error
Runtime error
damilojohn
commited on
Commit
Β·
fbd88a8
1
Parent(s):
3bf9f44
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,67 @@
|
|
1 |
-
|
2 |
-
from
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import EncoderDecoderModel,GPT2LMHeadModel,BertTokenizer
|
2 |
+
from datasets import load_dataset
|
3 |
+
import gradio as gr
|
4 |
+
import pandas as pd
|
5 |
+
import torch
|
6 |
+
|
7 |
+
|
8 |
+
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
|
9 |
+
Model = EncoderDecoderModel.from_pretrained('/content/drive/MyDrive/Models/Bert2BertForDescrambling')
|
10 |
+
def descramble(prompt):
|
11 |
+
input = tokenizer(prompt,return_tensors='pt')
|
12 |
+
input_id = input.input_ids
|
13 |
+
attention_mask = input.attention_mask
|
14 |
+
max_length = len(prompt.split(' '))
|
15 |
+
output = Model.generate(input_ids=input_id,attention_mask=attention_mask,)
|
16 |
+
output = tokenizer.decode(output[0],skip_special_tokens=True)
|
17 |
+
return gr.Textbox.update(value=output)
|
18 |
+
|
19 |
+
def set_example(example):
|
20 |
+
return gr.TextArea.update(value=example[0])
|
21 |
+
|
22 |
+
demo = gr.Blocks()
|
23 |
+
with demo:
|
24 |
+
gr.Markdown(
|
25 |
+
'''
|
26 |
+
# A Text Descrambler ππ
|
27 |
+
Turn your Incoherent Sentences to Grammatically correct Sentences.
|
28 |
+
This was built using transformers and Gradio
|
29 |
+
''')
|
30 |
+
with gr.Row():
|
31 |
+
with gr.Column():
|
32 |
+
gr.Markdown(
|
33 |
+
'''
|
34 |
+
Enter a meaningless sentence here
|
35 |
+
|
36 |
+
''')
|
37 |
+
prompt = gr.TextArea(
|
38 |
+
value = examples[0][0],
|
39 |
+
placeholder = "Enter A Text to see it's correct form "
|
40 |
+
)
|
41 |
+
example_prompts = gr.Dataset(
|
42 |
+
components = [prompt],
|
43 |
+
samples = examples)
|
44 |
+
with gr.Column():
|
45 |
+
find_answer = gr.Button('Click here to generate your sentence ππ€Ί').style(full_width=False)
|
46 |
+
with gr.Column():
|
47 |
+
answer = gr.Textbox(label='Answer',placeholder = "Correct Form")
|
48 |
+
with gr.Column():
|
49 |
+
gr.Markdown(
|
50 |
+
'''
|
51 |
+
## Still Under Construction ππβ³,
|
52 |
+
anything you see take it like that
|
53 |
+
''')
|
54 |
+
find_answer.click(
|
55 |
+
fn=descramble,
|
56 |
+
inputs=[prompt],
|
57 |
+
outputs=[answer]
|
58 |
+
)
|
59 |
+
example_prompts.click(
|
60 |
+
fn=set_example,
|
61 |
+
inputs=[example_prompts],
|
62 |
+
outputs=example_prompts.components,
|
63 |
+
)
|
64 |
+
|
65 |
+
|
66 |
+
|
67 |
+
demo.launch(debug=True)
|