File size: 3,057 Bytes
894cbe7
5eb7463
fbd88a8
 
 
 
9e8b8f9
fbd88a8
0557990
fbd88a8
 
 
 
 
 
 
 
6cd3be5
 
 
 
 
 
 
 
 
 
 
56cd8ba
020e9ac
fbd88a8
6a69ba8
fbd88a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17256a2
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
68
69
70
71
72
73
74
75
76
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()