File size: 4,173 Bytes
5558e45
da2c9bd
14637b5
da2c9bd
 
 
a204dfd
da2c9bd
14637b5
da2c9bd
a204dfd
3cb6db9
da2c9bd
 
 
 
 
 
3cb6db9
da2c9bd
3cb6db9
da2c9bd
 
3cb6db9
da2c9bd
 
 
 
 
 
beba0cd
4df79e9
da2c9bd
a204dfd
fd0291a
a204dfd
3cb6db9
 
fd0291a
da2c9bd
3c9ea56
ab2e1ab
 
7ac57fe
14637b5
fc0ac32
 
14637b5
3cb6db9
d2905e7
5c133e7
ee72d9a
 
d2905e7
ee72d9a
 
91d2eb2
 
 
 
 
497610f
 
919851b
c0bbee8
 
 
 
 
 
 
 
 
 
 
919851b
 
 
 
fc0ac32
3c9ea56
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import gradio as gr
import pandas as pd
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
from sklearn.model_selection import train_test_split
from sklearn.svm import SVR


data = pd.read_csv("modeled_data.csv")
analyzer = SentimentIntensityAnalyzer()


def sample_model(df, regressor):
    X = df.drop("rate",axis=1)
    y = df["rate"]
    
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state=1)
    
    model = regressor
    model.fit(X_train, y_train)
    
    return model


def calculate_sentiments(comment, model):
    
    negative_score = analyzer.polarity_scores(comment)["neg"]
    neutral_score = analyzer.polarity_scores(comment)["neu"]
    positive_score = analyzer.polarity_scores(comment)["pos"]
    compound_score = analyzer.polarity_scores(comment)["compound"]
    rate_pred = model.predict([[negative_score, neutral_score, positive_score, compound_score]])
    
    return round(negative_score,2), round(neutral_score,2), round(positive_score,2), round(compound_score,2), round(rate_pred[0],2)

    
def take_input(comment):
    
    cons_tuned_svr = sample_model(data, SVR(C=3, kernel="rbf", tol=0.001))
    return calculate_sentiments(comment, cons_tuned_svr)


with gr.Blocks() as demo:
    gr.Markdown("# AIN311 Project P05 - MOOC Recommendation")
    gr.Markdown("## Generating a Rating from User Comment")
    with gr.Column():
        gr.Markdown("""
                    ##### Thanks for your interest and taking your time.
                    ##### Tell us about your personal experience enrolling in this course. Was it the right match for you?
                    """)
        input_comment = gr.Textbox(placeholder="Write your comment here...", show_label = False, lines=2)
        button = gr.Button("What is the Rating I Have Given? Click me to Learn", variant="secondary").style(full_width=True)
        with gr.Row():
            with gr.Column():
                gr.Markdown("#### Generated Rating from Your Comment")
                rating = gr.Number().style(show_label=False)
            with gr.Column():
                gr.Markdown("#### Sentiment Scores of Your Comment")
                with gr.Row():
                    negscore = gr.Number(label="Negativity Score")
                    neuscore = gr.Number(label="Neutrality Score")
                    posscore = gr.Number(label="Positivity Score")
                    compscore = gr.Number(label="Compound Score")

        gr.Markdown("Example comments has taken from https://www.udemy.com/course/statistics-for-data-science-and-business-analysis/")
        gr.Examples(
                     [["Not really a basic course. Goes too fast and sometimes the explanations aren't clear. The solutions to the exercises are not explained, and should be. Not much better than the other course I started and didn't finish.(3)"], 
                      ["Presentation style was bad. Too much detail on the simpler topics, and glossed over some of the more complicated ones.(2)"], 
                      ["This course is the worst Course i have ever watched (1)"],
                      ["The course is really great! The didatic in explain all concepts and pratical examples are amazing. Better than brazilian universities.(4)"],
                      ["The best!!!!!!!!!!(5)"],
                      ["Excelent description and view. The exercises were prepared very carefully. I suggest it.(5)"],
                      ["Yes, This course is a very good way to update/ refresh statistical knowledge (2)"],
                      ["explaination is good but practical examples are not so good (2.5)"],
                      ["Thanks for content. Good to know and understand the things easily. (3.5)"],
                      ["good (3)"],
                      ["The course navigation is very bad ..It is very tedious to navigate the course.(5)"]],
                     [input_comment],
                     [[negscore, neuscore, posscore, compscore, rating]],
                     fn=take_input
        )
    button.click(fn=take_input, inputs=input_comment, outputs=[negscore, neuscore, posscore, compscore, rating])

demo.launch()