Spaces:
Runtime error
Runtime error
Update comment_analyzer.py
Browse files- comment_analyzer.py +7 -20
comment_analyzer.py
CHANGED
@@ -1,20 +1,17 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
-
|
5 |
-
#pip install langdetect
|
6 |
from langdetect import detect
|
7 |
-
|
8 |
-
#pip install vaderSentiment
|
9 |
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
10 |
-
|
11 |
from sklearn.model_selection import train_test_split
|
12 |
from sklearn.svm import SVR
|
13 |
from sklearn.metrics import mean_squared_error
|
14 |
|
|
|
15 |
data = pd.read_csv("modeled_data.csv")
|
16 |
analyzer = SentimentIntensityAnalyzer()
|
17 |
|
|
|
18 |
def sample_model(df, regressor, scale=None):
|
19 |
X = df.drop("rate",axis=1)
|
20 |
y = df["rate"]
|
@@ -44,26 +41,14 @@ def user_interaction(comment, model):
|
|
44 |
rate_pred = model.predict([[negative_score, neutral_score, positive_score, compound_score]])
|
45 |
|
46 |
return round(negative_score,2), round(neutral_score,2), round(positive_score,2), round(compound_score,2), round(rate_pred[0],2)
|
47 |
-
"""return (f"\nYour Comment: {comment}\n" +
|
48 |
-
"*"*10 + "Analysis of the Comment" + "*"*10 + "\n" +
|
49 |
-
"-"*10 + f"Negativity Score: {negative_score:.2f}" + "-"*10 + "\n" +
|
50 |
-
"-"*10 + f"Neutrality Score: {neutral_score:.2f}" + "-"*10 + "\n" +
|
51 |
-
"-"*10 + f"Positivity Score: {positive_score:.2f}" + "-"*10 + "\n" +
|
52 |
-
"-"*10 + f"Compound Score: {compound_score:.2f}" + "-"*10 + "\n" +
|
53 |
-
"*"*43 + "\n"), ("\nThe estimated rating this comment can give" + "\n" +
|
54 |
-
"*"*20 + str(round(rate_pred[0], 2)) + "*"*20 + "\n")"""
|
55 |
-
|
56 |
|
|
|
57 |
def take_input(comment):
|
58 |
-
|
59 |
-
# return "Sorry, your comment does not meet the requirements.\n", "Please check your comment"
|
60 |
-
#else:
|
61 |
cons_tuned_svr, _, _, _, _ = sample_model(data, SVR(C=3, kernel="rbf", tol=0.001))
|
62 |
return user_interaction(comment, cons_tuned_svr)
|
63 |
|
64 |
|
65 |
-
|
66 |
-
|
67 |
with gr.Blocks() as demo:
|
68 |
gr.Markdown("# AIN311 Project P05 - MOOC Recommendation")
|
69 |
gr.Markdown("## Generating a Rating from User Comment")
|
@@ -75,12 +60,14 @@ with gr.Blocks() as demo:
|
|
75 |
""")
|
76 |
input_comment = gr.Textbox(placeholder="Write your comment here...")
|
77 |
button = gr.Button("What is the Rating I Gave? Click me to Learn")
|
|
|
78 |
gr.Markdown("#### Sentiment Scores of Your Comment")
|
79 |
negscore = gr.Number(label="Negativity Score")
|
80 |
neuscore = gr.Number(label="Neutrality Score")
|
81 |
posscore = gr.Number(label="Positivity Score")
|
82 |
compscore = gr.Number(label="Compound Score")
|
83 |
-
rating = gr.Number(label="Generated Rating from Your Comment")
|
|
|
84 |
button.click(fn=take_input, inputs=input_comment, outputs=[negscore, neuscore, posscore, compscore, rating])
|
85 |
|
86 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
|
|
|
|
4 |
from langdetect import detect
|
|
|
|
|
5 |
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
|
|
6 |
from sklearn.model_selection import train_test_split
|
7 |
from sklearn.svm import SVR
|
8 |
from sklearn.metrics import mean_squared_error
|
9 |
|
10 |
+
|
11 |
data = pd.read_csv("modeled_data.csv")
|
12 |
analyzer = SentimentIntensityAnalyzer()
|
13 |
|
14 |
+
|
15 |
def sample_model(df, regressor, scale=None):
|
16 |
X = df.drop("rate",axis=1)
|
17 |
y = df["rate"]
|
|
|
41 |
rate_pred = model.predict([[negative_score, neutral_score, positive_score, compound_score]])
|
42 |
|
43 |
return round(negative_score,2), round(neutral_score,2), round(positive_score,2), round(compound_score,2), round(rate_pred[0],2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
+
|
46 |
def take_input(comment):
|
47 |
+
|
|
|
|
|
48 |
cons_tuned_svr, _, _, _, _ = sample_model(data, SVR(C=3, kernel="rbf", tol=0.001))
|
49 |
return user_interaction(comment, cons_tuned_svr)
|
50 |
|
51 |
|
|
|
|
|
52 |
with gr.Blocks() as demo:
|
53 |
gr.Markdown("# AIN311 Project P05 - MOOC Recommendation")
|
54 |
gr.Markdown("## Generating a Rating from User Comment")
|
|
|
60 |
""")
|
61 |
input_comment = gr.Textbox(placeholder="Write your comment here...")
|
62 |
button = gr.Button("What is the Rating I Gave? Click me to Learn")
|
63 |
+
|
64 |
gr.Markdown("#### Sentiment Scores of Your Comment")
|
65 |
negscore = gr.Number(label="Negativity Score")
|
66 |
neuscore = gr.Number(label="Neutrality Score")
|
67 |
posscore = gr.Number(label="Positivity Score")
|
68 |
compscore = gr.Number(label="Compound Score")
|
69 |
+
rating = gr.Number(label="Generated Rating from Your Comment")
|
70 |
+
|
71 |
button.click(fn=take_input, inputs=input_comment, outputs=[negscore, neuscore, posscore, compscore, rating])
|
72 |
|
73 |
demo.launch()
|