File size: 1,437 Bytes
090b1b7
 
ba275d7
e36bf2f
090b1b7
a2ce6e9
 
 
 
ba275d7
 
 
 
 
 
 
 
 
 
 
090b1b7
 
 
ba275d7
 
 
 
090b1b7
ba275d7
 
 
 
 
 
 
 
 
090b1b7
 
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
import gradio as gr
import nlpaug.augmenter.word as naw
import nlpaug.augmenter.char as nac
import nlpaug.augmenter.sentence as nas

import nltk
nltk.download('averaged_perceptron_tagger')
nltk.download('wordnet')

# Function for NLP augmentation
def augment_text(text, method):
    if method == "Synonym Replacement":
        aug = naw.SynonymAug(aug_src="wordnet", aug_max=3)
    elif method == "Word Embedding Substitution":
        aug = naw.WordEmbsAug(model_type='word2vec', model_path="GoogleNews-vectors-negative300.bin", action="substitute")
    elif method == "Contextual Word Insertion":
        aug = naw.ContextualWordEmbsAug(model_path="bert-base-uncased", action="insert")
    elif method == "Back Translation":
        aug = naw.BackTranslationAug(from_model_name='facebook/wmt19-en-de', to_model_name='facebook/wmt19-de-en')
    
    augmented_text = aug.augment(text)
    return augmented_text

# Gradio Interface
def nlp_augmentor_interface(text, method):
    augmented_text = augment_text(text, method)
    return augmented_text

iface = gr.Interface(
    fn=nlp_augmentor_interface,
    inputs=[
        gr.Textbox(lines=2, placeholder="Enter sentence to augment here..."),
        gr.Radio(["Synonym Replacement", "Word Embedding Substitution", "Contextual Word Insertion", "Back Translation"], label="Augmentation Method")
    ],
    outputs="text",
    title="NLP Text Augmentation with Gradio"
)

iface.launch()