MAli7319 commited on
Commit
3cb6db9
·
1 Parent(s): 91d2eb2

Update comment_analyzer.py

Browse files
Files changed (1) hide show
  1. comment_analyzer.py +9 -14
comment_analyzer.py CHANGED
@@ -12,27 +12,22 @@ 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"]
18
 
19
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state=1)
20
- scaled_X_train, scaled_X_test = X_train, X_test
21
- if scale != None:
22
- scaler = scale
23
- scaled_X_train = pd.DataFrame(scaler.fit_transform(X_train), columns = X_train.columns)
24
- scaled_X_test = pd.DataFrame(scaler.transform(X_test),columns = X_test.columns)
25
 
26
  model = regressor
27
- model.fit(scaled_X_train, y_train)
28
- y_pred = model.predict(scaled_X_test)
29
 
30
  rmse = np.sqrt(mean_squared_error(y_test, y_pred))
31
 
32
- return model, scaled_X_train, scaled_X_test, y_train, y_test
33
 
34
 
35
- def user_interaction(comment, model):
36
 
37
  negative_score = analyzer.polarity_scores(comment)["neg"]
38
  neutral_score = analyzer.polarity_scores(comment)["neu"]
@@ -45,8 +40,8 @@ def user_interaction(comment, model):
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:
@@ -57,8 +52,8 @@ with gr.Blocks() as demo:
57
  ##### Thanks for your interest and taking your time.
58
  ##### Tell us about your personal experience enrolling in this course. Was it the right match for you?
59
  """)
60
- input_comment = gr.Textbox(placeholder="Write your comment here...", show_label = False)
61
- button = gr.Button("What is the Rating I Have Given? Click me to Learn")
62
  with gr.Row():
63
  with gr.Column():
64
  gr.Markdown("#### Generated Rating from Your Comment")
 
12
  analyzer = SentimentIntensityAnalyzer()
13
 
14
 
15
+ def sample_model(df, regressor):
16
  X = df.drop("rate",axis=1)
17
  y = df["rate"]
18
 
19
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state=1)
 
 
 
 
 
20
 
21
  model = regressor
22
+ model.fit(X_train, y_train)
23
+ y_pred = model.predict(X_test)
24
 
25
  rmse = np.sqrt(mean_squared_error(y_test, y_pred))
26
 
27
+ return model
28
 
29
 
30
+ def calculate_sentiments(comment, model):
31
 
32
  negative_score = analyzer.polarity_scores(comment)["neg"]
33
  neutral_score = analyzer.polarity_scores(comment)["neu"]
 
40
 
41
  def take_input(comment):
42
 
43
+ cons_tuned_svr = sample_model(data, SVR(C=3, kernel="rbf", tol=0.001))
44
+ return calculate_sentiments(comment, cons_tuned_svr)
45
 
46
 
47
  with gr.Blocks() as demo:
 
52
  ##### Thanks for your interest and taking your time.
53
  ##### Tell us about your personal experience enrolling in this course. Was it the right match for you?
54
  """)
55
+ input_comment = gr.Textbox(placeholder="Write your comment here...", show_label = False, lines=2)
56
+ button = gr.Button("What is the Rating I Have Given? Click me to Learn", variant="primary").style(full_width=True)
57
  with gr.Row():
58
  with gr.Column():
59
  gr.Markdown("#### Generated Rating from Your Comment")