Update app.py
Browse files
app.py
CHANGED
|
@@ -37,23 +37,16 @@ else:
|
|
| 37 |
model = ORTModelForSequenceClassification.from_pretrained(model_id)
|
| 38 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 39 |
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
def classify_text(text):
|
| 43 |
results = pipe(text)
|
| 44 |
output = ""
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
output += f"Label 1: {
|
| 49 |
-
|
| 50 |
-
# Print the second result if it exists
|
| 51 |
-
if len(results) > 1:
|
| 52 |
-
output += f"Label 2: {results[1]['label']}, Score: {results[1]['score']:.4f}\n"
|
| 53 |
-
|
| 54 |
-
# Print the third result if it exists
|
| 55 |
-
if len(results) > 2:
|
| 56 |
-
output += f"Label 3: {results[2]['label']}, Score: {results[2]['score']:.4f}\n"
|
| 57 |
|
| 58 |
return output
|
| 59 |
|
|
|
|
| 37 |
model = ORTModelForSequenceClassification.from_pretrained(model_id)
|
| 38 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 39 |
|
| 40 |
+
# Set top_k=3 to get the top 3 results
|
| 41 |
+
pipe = pipeline(task="text-classification", model=model, tokenizer=tokenizer, top_k=3)
|
| 42 |
|
| 43 |
def classify_text(text):
|
| 44 |
results = pipe(text)
|
| 45 |
output = ""
|
| 46 |
|
| 47 |
+
# Loop through up to 3 results
|
| 48 |
+
for i, result in enumerate(results[:3]):
|
| 49 |
+
output += f"Label {i+1}: {result['label']}, Score: {result['score']:.4f}\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
return output
|
| 52 |
|