Spaces:
Running
on
Zero
Running
on
Zero
update text color
Browse files- app_text.py +5 -1
app_text.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
# %%
|
|
|
2 |
import os
|
3 |
USE_HUGGINGFACE_ZEROGPU = os.getenv("USE_HUGGINGFACE_ZEROGPU", "False").lower() in ["true", "1", "yes"]
|
4 |
-
#%%
|
5 |
if USE_HUGGINGFACE_ZEROGPU: # huggingface ZeroGPU, dynamic GPU allocation
|
6 |
try:
|
7 |
import spaces
|
@@ -98,14 +98,18 @@ def make_plot(token_texts, rgb, num_lines=50, title=""):
|
|
98 |
x_pos = 0.0
|
99 |
max_word_length = max(len(word) for word in words)
|
100 |
count = 0
|
|
|
101 |
for word, color in zip(words, colors):
|
|
|
102 |
if '\n' in word:
|
103 |
word = word.replace('\n', '')
|
|
|
104 |
y_pos -= 0.025
|
105 |
x_pos = 0.0
|
106 |
count += 1
|
107 |
if count >= num_lines:
|
108 |
break
|
|
|
109 |
|
110 |
text_color = 'black' if sum(mcolors.hex2color(color)) > 1.3 else 'white' # Choose text color based on background color
|
111 |
# text_color = 'black'
|
|
|
1 |
# %%
|
2 |
+
import copy
|
3 |
import os
|
4 |
USE_HUGGINGFACE_ZEROGPU = os.getenv("USE_HUGGINGFACE_ZEROGPU", "False").lower() in ["true", "1", "yes"]
|
|
|
5 |
if USE_HUGGINGFACE_ZEROGPU: # huggingface ZeroGPU, dynamic GPU allocation
|
6 |
try:
|
7 |
import spaces
|
|
|
98 |
x_pos = 0.0
|
99 |
max_word_length = max(len(word) for word in words)
|
100 |
count = 0
|
101 |
+
prev_word = ""
|
102 |
for word, color in zip(words, colors):
|
103 |
+
_word = copy.deepcopy(word)
|
104 |
if '\n' in word:
|
105 |
word = word.replace('\n', '')
|
106 |
+
if '\n' in prev_word:
|
107 |
y_pos -= 0.025
|
108 |
x_pos = 0.0
|
109 |
count += 1
|
110 |
if count >= num_lines:
|
111 |
break
|
112 |
+
prev_word = _word
|
113 |
|
114 |
text_color = 'black' if sum(mcolors.hex2color(color)) > 1.3 else 'white' # Choose text color based on background color
|
115 |
# text_color = 'black'
|