Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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(): #
|
| 23 |
-
outputs = model(**inputs)
|
| 24 |
-
predictions = outputs.logits #
|
| 25 |
-
predictions = torch.softmax(predictions, dim=-1) #
|
| 26 |
-
predictions = predictions.cpu().detach().numpy()[0] #
|
| 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
|