maximuspowers commited on
Commit
c19dfc1
·
verified ·
1 Parent(s): a2ce6e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -2,17 +2,29 @@ import gradio as gr
2
  import nlpaug.augmenter.word as naw
3
  import nlpaug.augmenter.char as nac
4
  import nlpaug.augmenter.sentence as nas
5
-
6
  import nltk
 
 
 
7
  nltk.download('averaged_perceptron_tagger')
8
  nltk.download('wordnet')
9
 
 
 
 
 
 
 
 
 
10
  # Function for NLP augmentation
11
  def augment_text(text, method):
12
  if method == "Synonym Replacement":
13
  aug = naw.SynonymAug(aug_src="wordnet", aug_max=3)
14
  elif method == "Word Embedding Substitution":
15
- aug = naw.WordEmbsAug(model_type='word2vec', model_path="GoogleNews-vectors-negative300.bin", action="substitute")
 
16
  elif method == "Contextual Word Insertion":
17
  aug = naw.ContextualWordEmbsAug(model_path="bert-base-uncased", action="insert")
18
  elif method == "Back Translation":
@@ -36,4 +48,4 @@ iface = gr.Interface(
36
  title="NLP Text Augmentation with Gradio"
37
  )
38
 
39
- iface.launch()
 
2
  import nlpaug.augmenter.word as naw
3
  import nlpaug.augmenter.char as nac
4
  import nlpaug.augmenter.sentence as nas
5
+ import os
6
  import nltk
7
+ from nlpaug.util.file.download import DownloadUtil
8
+
9
+ # Download necessary NLTK resources
10
  nltk.download('averaged_perceptron_tagger')
11
  nltk.download('wordnet')
12
 
13
+ # Function to download Word2Vec model if not available
14
+ def download_word2vec():
15
+ word2vec_path = "GoogleNews-vectors-negative300.bin"
16
+ if not os.path.exists(word2vec_path):
17
+ print("Downloading Word2Vec model...")
18
+ DownloadUtil.download_word2vec(dest_dir='.')
19
+ return word2vec_path
20
+
21
  # Function for NLP augmentation
22
  def augment_text(text, method):
23
  if method == "Synonym Replacement":
24
  aug = naw.SynonymAug(aug_src="wordnet", aug_max=3)
25
  elif method == "Word Embedding Substitution":
26
+ word2vec_path = download_word2vec() # Ensure the model is downloaded
27
+ aug = naw.WordEmbsAug(model_type='word2vec', model_path=word2vec_path, action="substitute")
28
  elif method == "Contextual Word Insertion":
29
  aug = naw.ContextualWordEmbsAug(model_path="bert-base-uncased", action="insert")
30
  elif method == "Back Translation":
 
48
  title="NLP Text Augmentation with Gradio"
49
  )
50
 
51
+ iface.launch(share=True)