poltextlab commited on
Commit
af93ecc
·
verified ·
1 Parent(s): 98dfbf2

update bar

Browse files
Files changed (1) hide show
  1. interfaces/cap_minor.py +8 -1
interfaces/cap_minor.py CHANGED
@@ -17,6 +17,11 @@ def take(n, iterable):
17
  """Return the first n items of the iterable as a list."""
18
  return list(islice(iterable, n))
19
 
 
 
 
 
 
20
  HF_TOKEN = os.environ["hf_read"]
21
 
22
  languages = [
@@ -89,6 +94,8 @@ def predict(text, model_id, tokenizer_id):
89
  text_color = "black"
90
  bar_width = int(prob * 100)
91
 
 
 
92
  if first:
93
  html += f"""
94
  <div style="display: flex; bold; font-size: 30px; justify-content: space-between; align-items: center; margin-bottom: 4px;">
@@ -101,7 +108,7 @@ def predict(text, model_id, tokenizer_id):
101
  <span style="color: {text_color};">{label}</span>
102
  <span style="color: {text_color};">{int(prob * 100)}%</span>
103
  </div>
104
- <div style="height: 4px; background: linear-gradient(to right, red, green); width: {bar_width}%; margin-bottom: 8px;"></div>
105
  """
106
  first = False
107
 
 
17
  """Return the first n items of the iterable as a list."""
18
  return list(islice(iterable, n))
19
 
20
+ def score_to_color(prob):
21
+ red = int(255 * (1 - prob))
22
+ green = int(255 * prob)
23
+ return f"rgb({red},{green},0)"
24
+
25
  HF_TOKEN = os.environ["hf_read"]
26
 
27
  languages = [
 
94
  text_color = "black"
95
  bar_width = int(prob * 100)
96
 
97
+ bar_color = score_to_color(prob)
98
+
99
  if first:
100
  html += f"""
101
  <div style="display: flex; bold; font-size: 30px; justify-content: space-between; align-items: center; margin-bottom: 4px;">
 
108
  <span style="color: {text_color};">{label}</span>
109
  <span style="color: {text_color};">{int(prob * 100)}%</span>
110
  </div>
111
+ <div style="height: 4px; background-color: {bar_color}; width: {bar_width}%; margin-bottom: 8px;"></div>
112
  """
113
  first = False
114