Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,28 +35,33 @@ def user_interaction(comment, model):
|
|
| 35 |
compound_score = analyzer.polarity_scores(comment)["compound"]
|
| 36 |
rate_pred = model.predict([[negative_score, neutral_score, positive_score, compound_score]])
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
|
| 49 |
def take_input(model):
|
| 50 |
-
comment = input("Thanks for your interest and taking your time.\n"+
|
| 51 |
-
"Tell us about your personal experience enrolling in this course. Was it the right match for you?\n"+
|
| 52 |
-
"(Note: Comment should be written in English and be longer than 20 characters)\n")
|
| 53 |
if (detect(comment) != "en") or (len(comment) < 20):
|
| 54 |
-
|
| 55 |
else:
|
| 56 |
-
user_interaction(comment, model)
|
| 57 |
|
| 58 |
cons_tuned_svr, _, _, _, _ = sample_model(data, SVR(C=3, kernel="rbf", tol=0.001))
|
| 59 |
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
compound_score = analyzer.polarity_scores(comment)["compound"]
|
| 36 |
rate_pred = model.predict([[negative_score, neutral_score, positive_score, compound_score]])
|
| 37 |
|
| 38 |
+
return f"\nYour Comment: {comment}\n" +
|
| 39 |
+
"*"*10 + "Analysis of the Comment" + "*"*10 +
|
| 40 |
+
"-"*10 + f"Negativity Score: {negative_score:.2f}" + "-"*10 +
|
| 41 |
+
"-"*10 + f"Neutrality Score: {neutral_score:.2f}" + "-"*10 +
|
| 42 |
+
"-"*10 + f"Positivity Score: {positive_score:.2f}" + "-"*10 +
|
| 43 |
+
"-"*10 + f"Compound Score: {compound_score:.2f}" + "-"*10 +
|
| 44 |
+
"*"*43,
|
| 45 |
+
"\nThe estimated rating this comment can give" +
|
| 46 |
+
"*"*20 + str(round(rate_pred[0], 2)) + "*"*20
|
| 47 |
|
| 48 |
|
| 49 |
def take_input(model):
|
|
|
|
|
|
|
|
|
|
| 50 |
if (detect(comment) != "en") or (len(comment) < 20):
|
| 51 |
+
return "Sorry, your comment does not meet the requirements.\n", "Please check your comment"
|
| 52 |
else:
|
| 53 |
+
return user_interaction(comment, model)
|
| 54 |
|
| 55 |
cons_tuned_svr, _, _, _, _ = sample_model(data, SVR(C=3, kernel="rbf", tol=0.001))
|
| 56 |
|
| 57 |
|
| 58 |
+
with gr.Blocks() as demo:
|
| 59 |
+
comment = gr.Textbox(label="Thanks for your interest and taking your time.\n"+
|
| 60 |
+
"Tell us about your personal experience enrolling in this course. Was it the right match for you?\n"+
|
| 61 |
+
"(Note: Comment should be written in English and be longer than 20 characters)\n")
|
| 62 |
+
comment_scores = gr.Textbox(label="Sentiment Scores of Your Comment")
|
| 63 |
+
rating = gr.Textbox(label="Generated Rating from Your Comment")
|
| 64 |
+
greet_btn = gr.Button("What is the Rating I Gave? Click me to Learn")
|
| 65 |
+
greet_btn.click(fn=greet, inputs=comment, outputs=[comment_scores, rating])
|
| 66 |
+
|
| 67 |
+
demo.launch()
|