Havoc999 commited on
Commit
267ccfe
·
verified ·
1 Parent(s): 8884cc2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -10
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
- # Hide background warning logs
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. Force into a plain Python list (destroys NumPy types instantly)
45
  clean_scores = scores_array.tolist()
46
 
47
- # 5. Extract items out one by one into independent variables
48
- negative_final_score = float(clean_scores)
49
- positive_final_score = float(clean_scores)
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(