-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
44 lines (39 loc) · 1.41 KB
/
app.py
File metadata and controls
44 lines (39 loc) · 1.41 KB
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
from keras.models import load_model
import joblib
from tensorflow.keras.preprocessing.sequence import pad_sequences
import re
import gradio as gr
# Load the pre-trained model and tokenizer
model = load_model("model.keras")
tokenizer = joblib.load("tokenizer.pkl")
# Define the predictive system
def predictive_system(review):
if not review.strip():
return "empty review"
elif review.strip().isnumeric():
return "review contains only numbers"
elif all(char in "!@#$%^&*()_+-=[]{}|;:',.<>?/`~ " for char in review):
return "review contains only symbols"
elif len(review.split()) == 1:
return "review is too short"
elif not re.search(r"[a-zA-Z]", review):
return "review is gibberish"
else:
sequences = tokenizer.texts_to_sequences([review])
padded_sequence = pad_sequences(sequences, maxlen=200)
prediction = model.predict(padded_sequence)
sentiment = "positive" if prediction[0][0] > 0.5 else "negative"
return sentiment
# Gradio Interface
title = "Movie Sentiment Analysis Using Machine Learning"
article = "<div style='text-align: center; padding-top: 50px;'><p>Created by <strong>Vipanshu Suman & Divyam Pathak</strong></p></div>"
app = gr.Interface(
fn=predictive_system,
inputs="textbox",
outputs="textbox",
title=title,
article=article
)
# Launch the app
if __name__ == "__main__":
app.launch(share=True)