WarTitan2077 commited on
Commit
14c3783
·
verified ·
1 Parent(s): 760b630

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -9
app.py CHANGED
@@ -45,21 +45,28 @@ def classify_numbers(input1, input2, input3):
45
  predictions = {}
46
 
47
  for i, value in enumerate(inputs):
48
- result = classifier(value)[0] # get top_k=None full result
49
- number_index = i + 1 # 1-based index: 1, 2, 3
50
 
51
- # Filter and rename labels specific to this input
52
- filtered = {
53
- label_map[item["label"]]: round(item["score"], 3)
54
- for item in result
55
- if label_map[item["label"]].endswith(str(number_index))
56
- }
57
 
58
- predictions[f"Input{number_index}"] = filtered
 
 
 
 
 
 
 
 
 
 
59
 
60
  return predictions
61
 
62
 
 
 
63
  # Gradio UI
64
  iface = gr.Interface(
65
  fn=classify_numbers,
 
45
  predictions = {}
46
 
47
  for i, value in enumerate(inputs):
48
+ result = classifier(value)[0] # full list of label scores
49
+ number_index = str(i + 1)
50
 
51
+ input_result = {}
 
 
 
 
 
52
 
53
+ for item in result:
54
+ label = label_map[item["label"]]
55
+ if label.endswith(number_index):
56
+ input_result[label] = round(item["score"], 3)
57
+
58
+ # ✅ Sort the results by score (highest to lowest)
59
+ input_result = dict(
60
+ sorted(input_result.items(), key=lambda x: x[1], reverse=True)
61
+ )
62
+
63
+ predictions[f"Input{number_index}"] = input_result
64
 
65
  return predictions
66
 
67
 
68
+
69
+
70
  # Gradio UI
71
  iface = gr.Interface(
72
  fn=classify_numbers,