Update app.py
Browse files
app.py
CHANGED
|
@@ -42,19 +42,19 @@ tokenizer = AutoTokenizer.from_pretrained(model_id)
|
|
| 42 |
pipe = pipeline(task="text-classification", model=model, tokenizer=tokenizer)
|
| 43 |
|
| 44 |
def classify_text(text):
|
| 45 |
-
start_time = time.time()
|
| 46 |
|
| 47 |
-
|
| 48 |
results = pipe(text, return_all_scores=True)
|
| 49 |
|
| 50 |
-
end_time = time.time()
|
| 51 |
|
| 52 |
output = f"Sentence: {text}\n"
|
| 53 |
|
| 54 |
-
|
| 55 |
sorted_results = sorted(results[0], key=lambda x: x['score'], reverse=True)
|
| 56 |
|
| 57 |
-
|
| 58 |
for i, result in enumerate(sorted_results[:3]): # Limiting to the top 3 results
|
| 59 |
output += f"Label {i+1}: {result['label']}, Score: {result['score']:.4f}\n"
|
| 60 |
|
|
@@ -62,7 +62,7 @@ def classify_text(text):
|
|
| 62 |
|
| 63 |
return output
|
| 64 |
|
| 65 |
-
|
| 66 |
gr.Interface(
|
| 67 |
fn=classify_text,
|
| 68 |
title="Sentiment Classifier",
|
|
|
|
| 42 |
pipe = pipeline(task="text-classification", model=model, tokenizer=tokenizer)
|
| 43 |
|
| 44 |
def classify_text(text):
|
| 45 |
+
# start_time = time.time()
|
| 46 |
|
| 47 |
+
|
| 48 |
results = pipe(text, return_all_scores=True)
|
| 49 |
|
| 50 |
+
# end_time = time.time()
|
| 51 |
|
| 52 |
output = f"Sentence: {text}\n"
|
| 53 |
|
| 54 |
+
|
| 55 |
sorted_results = sorted(results[0], key=lambda x: x['score'], reverse=True)
|
| 56 |
|
| 57 |
+
|
| 58 |
for i, result in enumerate(sorted_results[:3]): # Limiting to the top 3 results
|
| 59 |
output += f"Label {i+1}: {result['label']}, Score: {result['score']:.4f}\n"
|
| 60 |
|
|
|
|
| 62 |
|
| 63 |
return output
|
| 64 |
|
| 65 |
+
|
| 66 |
gr.Interface(
|
| 67 |
fn=classify_text,
|
| 68 |
title="Sentiment Classifier",
|