Spaces:
Runtime error
Runtime error
File size: 2,141 Bytes
fbd88a8 56cd8ba fbd88a8 56cd8ba fbd88a8 56cd8ba |
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
from transformers import EncoderDecoderModel,GPT2LMHeadModel,BertTokenizer
from datasets import load_dataset
import gradio as gr
import pandas as pd
import torch
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
Model = EncoderDecoderModel.from_pretrained('damilojohn/Bert2BertForTextDescrambling')
def descramble(prompt):
input = tokenizer(prompt,return_tensors='pt')
input_id = input.input_ids
attention_mask = input.attention_mask
max_length = len(prompt.split(' '))
output = Model.generate(input_ids=input_id,attention_mask=attention_mask,)
output = tokenizer.decode(output[0],skip_special_tokens=True)
return gr.Textbox.update(value=output)
def set_example(example):
return gr.TextArea.update(value=example[0])
demo = gr.Blocks()
with demo:
gr.Markdown(
'''
# A Text Descrambler ππ
Turn your Incoherent Sentences to Grammatically correct Sentences.
This was built using transformers and Gradio
''')
with gr.Row():
with gr.Column():
gr.Markdown(
'''
Enter a meaningless sentence here
''')
prompt = gr.TextArea(
value = examples[0][0],
placeholder = "Enter A Text to see it's correct form "
)
example_prompts = gr.Dataset(
components = [prompt],
samples = examples)
with gr.Column():
find_answer = gr.Button('Click here to generate your sentence ππ€Ί').style(full_width=False)
with gr.Column():
answer = gr.Textbox(label='Answer',placeholder = "Correct Form")
with gr.Column():
gr.Markdown(
'''
## Still Under Construction ππβ³,
anything you see take it like that
''')
find_answer.click(
fn=descramble,
inputs=[prompt],
outputs=[answer]
)
example_prompts.click(
fn=set_example,
inputs=[example_prompts],
outputs=example_prompts.components,
)
demo.launch() |