Spaces:
Sleeping
Sleeping
v0.1
Browse files- app.py +26 -23
- {lr โ models/lr}/model.pkl +0 -0
- {lr โ models/lr}/vectorizer.pkl +0 -0
- {mnb โ models/mnb}/model.pkl +0 -0
- {mnb โ models/mnb}/vectorizer.pkl +0 -0
- {rf โ models/rf}/model.pkl +0 -0
- {rf โ models/rf}/vectorizer.pkl +0 -0
- {svm โ models/svm}/model.pkl +0 -0
- {svm โ models/svm}/vectorizer.pkl +0 -0
- requirements.txt +3 -0
app.py
CHANGED
|
@@ -27,9 +27,6 @@ models = {
|
|
| 27 |
}
|
| 28 |
|
| 29 |
def predict_sentiment(message, model_name="MultinomialNB"):
|
| 30 |
-
if not message.strip():
|
| 31 |
-
return None
|
| 32 |
-
|
| 33 |
model, vectorizer = models[model_name]
|
| 34 |
preprocessed = preprocess_text(message)
|
| 35 |
vectorized = vectorizer.transform([preprocessed])
|
|
@@ -39,40 +36,46 @@ def predict_sentiment(message, model_name="MultinomialNB"):
|
|
| 39 |
def get_bot_response(message, chat_history, model_choice):
|
| 40 |
message = message["text"]
|
| 41 |
if not message.strip():
|
|
|
|
|
|
|
|
|
|
| 42 |
return "", chat_history
|
| 43 |
|
| 44 |
# Get sentiment prediction
|
| 45 |
sentiment = predict_sentiment(message, model_choice)
|
| 46 |
|
| 47 |
-
if sentiment is None:
|
| 48 |
-
bot_response = "Please share your thoughts about a game!"
|
| 49 |
-
chat_history.append((message, bot_response))
|
| 50 |
-
return "", chat_history
|
| 51 |
-
|
| 52 |
# Generate response based on sentiment
|
| 53 |
if sentiment == 1:
|
| 54 |
-
|
| 55 |
-
f"This is a Positive review ๐"
|
| 56 |
-
]
|
| 57 |
-
bot_response = responses[len(chat_history) % len(responses)]
|
| 58 |
else:
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
chat_history.append((message, bot_response))
|
| 65 |
return "", chat_history
|
| 66 |
|
| 67 |
# Create the Gradio interface
|
| 68 |
with gr.Blocks(theme=gr.themes.Default(), title="Gaming Sentiment Chatbot", css=".upload-button {display: none;} .centered-md {text-align: center}") as demo:
|
| 69 |
gr.Markdown("# ๐ฎ Steam Review Sentiment Analysis", elem_classes="centered-md")
|
| 70 |
-
gr.Markdown("
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
chatbot = gr.Chatbot(
|
|
|
|
| 74 |
label="History",
|
| 75 |
-
|
|
|
|
| 76 |
)
|
| 77 |
|
| 78 |
with gr.Row():
|
|
@@ -86,7 +89,7 @@ with gr.Blocks(theme=gr.themes.Default(), title="Gaming Sentiment Chatbot", css=
|
|
| 86 |
model_choice = gr.Dropdown(
|
| 87 |
choices=list(models.keys()),
|
| 88 |
value="MultinomialNB",
|
| 89 |
-
label="Select Model for Analysis",
|
| 90 |
)
|
| 91 |
|
| 92 |
# Example messages
|
|
@@ -97,7 +100,7 @@ with gr.Blocks(theme=gr.themes.Default(), title="Gaming Sentiment Chatbot", css=
|
|
| 97 |
"I can't believe how buggy this game is. Constant crashes and poor optimization.",
|
| 98 |
"Decent game but nothing special. Might be worth it on sale.",
|
| 99 |
"Best game I've played this year! The story is amazing!",
|
| 100 |
-
"1/10"
|
| 101 |
],
|
| 102 |
inputs=message,
|
| 103 |
label="Example Messages"
|
|
|
|
| 27 |
}
|
| 28 |
|
| 29 |
def predict_sentiment(message, model_name="MultinomialNB"):
|
|
|
|
|
|
|
|
|
|
| 30 |
model, vectorizer = models[model_name]
|
| 31 |
preprocessed = preprocess_text(message)
|
| 32 |
vectorized = vectorizer.transform([preprocessed])
|
|
|
|
| 36 |
def get_bot_response(message, chat_history, model_choice):
|
| 37 |
message = message["text"]
|
| 38 |
if not message.strip():
|
| 39 |
+
bot_response = "๐บ Please share a game review!"
|
| 40 |
+
chat_history.append({"role": "user", "content": message})
|
| 41 |
+
chat_history.append({"role": "assistant", "content": bot_response})
|
| 42 |
return "", chat_history
|
| 43 |
|
| 44 |
# Get sentiment prediction
|
| 45 |
sentiment = predict_sentiment(message, model_choice)
|
| 46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
# Generate response based on sentiment
|
| 48 |
if sentiment == 1:
|
| 49 |
+
bot_response = f"๐ธ This is a Positive review!"
|
|
|
|
|
|
|
|
|
|
| 50 |
else:
|
| 51 |
+
bot_response = f"๐พ This is a Negative review!"
|
| 52 |
+
|
| 53 |
+
chat_history.append({"role": "user", "content": message})
|
| 54 |
+
chat_history.append({"role": "assistant", "content": bot_response})
|
|
|
|
|
|
|
| 55 |
return "", chat_history
|
| 56 |
|
| 57 |
# Create the Gradio interface
|
| 58 |
with gr.Blocks(theme=gr.themes.Default(), title="Gaming Sentiment Chatbot", css=".upload-button {display: none;} .centered-md {text-align: center}") as demo:
|
| 59 |
gr.Markdown("# ๐ฎ Steam Review Sentiment Analysis", elem_classes="centered-md")
|
| 60 |
+
gr.Markdown("""
|
| 61 |
+
<div style="display: flex; justify-content: center; align-items: center; gap: 10px;">
|
| 62 |
+
โจ Enter a Steam review to analyze its sentiment. For more information, see the dataset used at:
|
| 63 |
+
<a href="https://www.kaggle.com/datasets/filipkin/steam-reviews" target="_blank">
|
| 64 |
+
<img src="https://img.shields.io/badge/Kaggle-Steam%20Reviews-blue?logo=kaggle" alt="Kaggle">
|
| 65 |
+
</a>
|
| 66 |
+
|
|
| 67 |
+
<a href="https://github.com/alyzbane/gradio-sentimental-analysis-ml" target="_blank">
|
| 68 |
+
<img src="https://img.shields.io/badge/GitHub-Repository-blue?logo=github" alt="GitHub">
|
| 69 |
+
</a>
|
| 70 |
+
</div>
|
| 71 |
+
""", elem_classes="centered-md")
|
| 72 |
+
|
| 73 |
|
| 74 |
chatbot = gr.Chatbot(
|
| 75 |
+
type="messages",
|
| 76 |
label="History",
|
| 77 |
+
placeholder="Share a though about video game ๐ฎ๐",
|
| 78 |
+
height=400,
|
| 79 |
)
|
| 80 |
|
| 81 |
with gr.Row():
|
|
|
|
| 89 |
model_choice = gr.Dropdown(
|
| 90 |
choices=list(models.keys()),
|
| 91 |
value="MultinomialNB",
|
| 92 |
+
label=r"โ Select Model for Analysis",
|
| 93 |
)
|
| 94 |
|
| 95 |
# Example messages
|
|
|
|
| 100 |
"I can't believe how buggy this game is. Constant crashes and poor optimization.",
|
| 101 |
"Decent game but nothing special. Might be worth it on sale.",
|
| 102 |
"Best game I've played this year! The story is amazing!",
|
| 103 |
+
"this game is 1/10 at best. Waste of money"
|
| 104 |
],
|
| 105 |
inputs=message,
|
| 106 |
label="Example Messages"
|
{lr โ models/lr}/model.pkl
RENAMED
|
File without changes
|
{lr โ models/lr}/vectorizer.pkl
RENAMED
|
File without changes
|
{mnb โ models/mnb}/model.pkl
RENAMED
|
File without changes
|
{mnb โ models/mnb}/vectorizer.pkl
RENAMED
|
File without changes
|
{rf โ models/rf}/model.pkl
RENAMED
|
File without changes
|
{rf โ models/rf}/vectorizer.pkl
RENAMED
|
File without changes
|
{svm โ models/svm}/model.pkl
RENAMED
|
File without changes
|
{svm โ models/svm}/vectorizer.pkl
RENAMED
|
File without changes
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==5.9.1
|
| 2 |
+
joblib==1.4.2
|
| 3 |
+
scikit_learn==1.6.0
|