Keetawan commited on
Commit
c9b77b5
·
1 Parent(s): f85ddaf

fix: pred time

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -2,6 +2,7 @@
2
  import torch
3
  import gradio as gr
4
  from model import SentimentAnalysisModel
 
5
 
6
  # Load the pre-trained sentiment analysis model
7
  model = SentimentAnalysisModel(bert_model_name="SamLowe/roberta-base-go_emotions", num_labels=7)
@@ -22,6 +23,7 @@ emoji_to_emotion = {
22
 
23
  # Function to make predictions
24
  def predict_sentiment(text):
 
25
  inputs = model.tokenizer(text, return_tensors="pt", truncation=True, padding=True)
26
  input_ids = inputs["input_ids"]
27
  attention_mask = inputs["attention_mask"]
@@ -31,11 +33,12 @@ def predict_sentiment(text):
31
 
32
  logits = outputs.logits
33
  _, predicted_class = torch.max(logits, dim=1)
 
34
 
35
  # Map predicted class to emoji
36
  result = emoji_to_emotion[predicted_class.item()]
37
 
38
- return result
39
 
40
  # Create title, description and article strings
41
  title = "Emoji-aware Sentiment Analysis using Roberta Model"
 
2
  import torch
3
  import gradio as gr
4
  from model import SentimentAnalysisModel
5
+ from timeit import default_timer as timer
6
 
7
  # Load the pre-trained sentiment analysis model
8
  model = SentimentAnalysisModel(bert_model_name="SamLowe/roberta-base-go_emotions", num_labels=7)
 
23
 
24
  # Function to make predictions
25
  def predict_sentiment(text):
26
+ start_time = timer()
27
  inputs = model.tokenizer(text, return_tensors="pt", truncation=True, padding=True)
28
  input_ids = inputs["input_ids"]
29
  attention_mask = inputs["attention_mask"]
 
33
 
34
  logits = outputs.logits
35
  _, predicted_class = torch.max(logits, dim=1)
36
+ pred_time = round(timer() - start_time, 5)
37
 
38
  # Map predicted class to emoji
39
  result = emoji_to_emotion[predicted_class.item()]
40
 
41
+ return result,pred_time
42
 
43
  # Create title, description and article strings
44
  title = "Emoji-aware Sentiment Analysis using Roberta Model"