Spaces:
Runtime error
Runtime error
import transformers | |
from transformers import EncoderDecoderModel,BertTokenizer | |
import gradio as gr | |
import pandas as pd | |
import torch | |
#loading tokenizer and model | |
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) | |
examples = [['layer Neurons receptive of input visual develop cortex primates in edge-like primary in the fields.'], | |
['of role unknown. still is in largely the representations homeostasis sparse such learning specific However,'], | |
['coding sparse is fair. optimized it when is Competition in'], | |
['sparse excitatory neurons. of inhibitory connections populations and and separate'], | |
['E. in proteins to oscillation Ongoing is Min required minicelling coli. block of sub-cellular'], | |
['Experimentally, newly and divided are Min minicells produced. cells no are in seen oscillations'], | |
['this behavior been role of sedentary has determined. The in not defect'], | |
['connections models These have for and important consequences of dynamics protein thermodynamics.'], | |
['plays role metric classification. The an important (NN) in nearest neighbor distance'], | |
['physiologically monostability. likely more That within ranges for multistability plausible becomes parameters, is, than']] | |
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( | |
''' | |
## Under Construction β³, | |
''') | |
find_answer.click( | |
fn=descramble, | |
inputs=[prompt], | |
outputs=[answer] | |
) | |
example_prompts.click( | |
fn=set_example, | |
inputs=[example_prompts], | |
outputs=example_prompts.components, | |
) | |
demo.launch() |