BraydenAC commited on
Commit
1fbe29c
Β·
verified Β·
1 Parent(s): ba566f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -3
app.py CHANGED
@@ -1,7 +1,38 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!"
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  demo.launch()
 
1
  import gradio as gr
2
+ from tensorflow import keras
3
+ import pandas as pd
4
+ import tensorflow as tf
5
+ import nltk
6
+ import spacy
7
+ import re
8
+ from nltk.corpus import stopwords
9
+ from nltk.tokenize import word_tokenize
10
+ from tensorflow.keras.preprocessing.text import Tokenizer
11
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
12
 
13
+ nltk.download('punkt_tab')
14
+ nltk.download('stopwords')
15
+ stop_words = set(stopwords.words('english'))
16
+ nlp = spacy.load('en_core_web_sm')
17
 
18
+ model = tf.keras.models.load_model("path_to_your_model/my_keras_model")
19
+
20
+ def preprocess_text(text):
21
+ text = re.sub(r'[^a-zA-Z0-9\s]', '', text) # Only remove non-alphanumeric characters except spaces
22
+
23
+ # Tokenize and remove stopwords
24
+ tokens = word_tokenize(text.lower())
25
+ tokens = [word for word in tokens if word not in stop_words]
26
+
27
+ # Lemmatize
28
+ doc = nlp(' '.join(tokens))
29
+ lemmas = [token.lemma_ for token in doc]
30
+ return ' '.join(lemmas)
31
+
32
+ def predict(text):
33
+ inputs = preprocess_text(text)
34
+ outputs = model(inputs)
35
+ return "This text is a violation = " + outputs
36
+
37
+ demo = gr.Interface(fn=predict, inputs="text", outputs="text")
38
  demo.launch()