arjahojnik commited on
Commit
be6a310
·
verified ·
1 Parent(s): 6dc2a07

Upload demo

Browse files
Files changed (3) hide show
  1. best_GRU_tuning_model.h5 +3 -0
  2. demo_launch.py +33 -0
  3. my_tokenizer.pkl +3 -0
best_GRU_tuning_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:63df9e0a0aea525a8faf6bee64c37bdb677bd3857e551151fe649f8fe348b0f9
3
+ size 4500792
demo_launch.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from tensorflow.keras.models import load_model
4
+ from tensorflow.keras.preprocessing.sequence import pad_sequences
5
+ import pickle
6
+ import re
7
+
8
+ # Load model and tokenizer
9
+ model = load_model("best_GRU_tuning_model.h5")
10
+ with open("my_tokenizer.pkl","rb") as f:
11
+ tokenizer = pickle.load(f)
12
+
13
+
14
+ def preprocess_text(text):
15
+ text = text.lower()
16
+ text = re.sub(r'[^a-zA-Z\s]', '', text).strip()
17
+ return text
18
+
19
+
20
+ def predict_sentiment(raw_text):
21
+ cleaned = preprocess_text(raw_text)
22
+ seq = tokenizer.texts_to_sequences([cleaned])
23
+ padded_seq = pad_sequences(seq, maxlen=200)
24
+ probs = model.predict(padded_seq)
25
+ predicted_class = np.argmax(probs, axis=1)[0]
26
+ rating = predicted_class + 1
27
+ return f"Predicted rating: {rating} (probabilities={probs[0]})"
28
+
29
+
30
+ demo = gr.Interface(fn=predict_sentiment,
31
+ inputs="text",
32
+ outputs="label")
33
+ demo.launch()
my_tokenizer.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0ec7e5e4490233566c1eba5de3e26696ce37b3bc12d5db5ea0b24dd949846d3e
3
+ size 2484227