Update app.py
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import gradio as gr
|
|
| 5 |
from transformers import AutoTokenizer
|
| 6 |
from huggingface_hub import hf_hub_download
|
| 7 |
|
| 8 |
-
#
|
| 9 |
os.environ["TRANSFORMERS_NO_ADVISORY_WARNINGS"] = "1"
|
| 10 |
|
| 11 |
REPO_ID = "Havoc999/distilbert-imdb-sentiment-onnx"
|
|
@@ -41,17 +41,12 @@ def predict_sentiment(text):
|
|
| 41 |
exp_logits = np.exp(logits - np.max(logits))
|
| 42 |
scores_array = exp_logits / np.sum(exp_logits)
|
| 43 |
|
| 44 |
-
# 4.
|
| 45 |
clean_scores = scores_array.tolist()
|
| 46 |
|
| 47 |
-
# 5.
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
return {
|
| 52 |
-
"Negative 🎬❌": negative_final_score,
|
| 53 |
-
"Positive 🍿✅": positive_final_score
|
| 54 |
-
}
|
| 55 |
|
| 56 |
# 6. Set up the web interface
|
| 57 |
demo = gr.Interface(
|
|
|
|
| 5 |
from transformers import AutoTokenizer
|
| 6 |
from huggingface_hub import hf_hub_download
|
| 7 |
|
| 8 |
+
# Silence background warning logs
|
| 9 |
os.environ["TRANSFORMERS_NO_ADVISORY_WARNINGS"] = "1"
|
| 10 |
|
| 11 |
REPO_ID = "Havoc999/distilbert-imdb-sentiment-onnx"
|
|
|
|
| 41 |
exp_logits = np.exp(logits - np.max(logits))
|
| 42 |
scores_array = exp_logits / np.sum(exp_logits)
|
| 43 |
|
| 44 |
+
# 4. Convert NumPy array directly to standard Python floats inside a list
|
| 45 |
clean_scores = scores_array.tolist()
|
| 46 |
|
| 47 |
+
# 5. NO INDEXES OR FLICKERING TYPOS: Map labels directly to values
|
| 48 |
+
labels = ["Negative 🎬❌", "Positive 🍿✅"]
|
| 49 |
+
return dict(zip(labels, clean_scores))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# 6. Set up the web interface
|
| 52 |
demo = gr.Interface(
|