EmmaL1 commited on
Commit
6c821ff
·
verified ·
1 Parent(s): 82362e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -19,11 +19,11 @@ def textclassification():
19
  if user_input:
20
  # Tokenize input and get model predictions
21
  inputs = tokenizer(user_input, return_tensors="pt", truncation=True, padding=True)
22
- with torch.no_grad(): # No gradient calculation for inference
23
- outputs = model(**inputs)
24
- predictions = outputs.logits # Raw logits (before softmax)
25
- predictions = torch.softmax(predictions, dim=-1) # Convert to probabilities
26
- predictions = predictions.cpu().detach().numpy()[0] # Convert to NumPy array
27
 
28
  # Calculate rating (1-5 stars)
29
  rating = np.argmax(predictions) + 1 # Index 0-4 -> 1-5 stars
 
19
  if user_input:
20
  # Tokenize input and get model predictions
21
  inputs = tokenizer(user_input, return_tensors="pt", truncation=True, padding=True)
22
+ with torch.no_grad(): # Line 23
23
+ outputs = model(**inputs) # Line 24
24
+ predictions = outputs.logits # Line 25
25
+ predictions = torch.softmax(predictions, dim=-1) # Line 26
26
+ predictions = predictions.cpu().detach().numpy()[0] # Line 27
27
 
28
  # Calculate rating (1-5 stars)
29
  rating = np.argmax(predictions) + 1 # Index 0-4 -> 1-5 stars