Update app.py
Browse files
app.py
CHANGED
@@ -110,53 +110,6 @@ def get_word_probabilities(text):
|
|
110 |
word_probs = [float(p) for p in word_probs]
|
111 |
return word_probs, word_colors
|
112 |
|
113 |
-
# def get_word_classifications(text):
|
114 |
-
# text = " ".join(text.split(" ")[:2048])
|
115 |
-
# inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
116 |
-
# inputs = {k: v.to(device) for k, v in inputs.items()}
|
117 |
-
# tokens = tokenizer.convert_ids_to_tokens(inputs["input_ids"][0])
|
118 |
-
|
119 |
-
# with torch.no_grad():
|
120 |
-
# tags, emissions = model(input_ids=inputs["input_ids"], attention_mask=inputs["attention_mask"])
|
121 |
-
|
122 |
-
# word_tags = []
|
123 |
-
# color_output = []
|
124 |
-
# current_word = ""
|
125 |
-
# current_prob = 0.0
|
126 |
-
|
127 |
-
# for token, prob in zip(tokens, tags[0]):
|
128 |
-
# if token in ["<s>", "</s>"]:
|
129 |
-
# continue
|
130 |
-
# if token.startswith("▁"):
|
131 |
-
# if current_word:
|
132 |
-
# word_tags.append(round(current_prob, 3))
|
133 |
-
# color = (
|
134 |
-
# "green" if current_prob < 0.25 else
|
135 |
-
# "yellow" if current_prob < 0.5 else
|
136 |
-
# "orange" if current_prob < 0.75 else
|
137 |
-
# "red"
|
138 |
-
# )
|
139 |
-
# color_output.append(f'<span style="color:{color}">{current_word}</span>')
|
140 |
-
# current_word = token[1:] if token != "▁" else ""
|
141 |
-
# current_prob = prob
|
142 |
-
# else:
|
143 |
-
# current_word += token
|
144 |
-
# current_prob = max(current_prob, prob)
|
145 |
-
|
146 |
-
# if current_word:
|
147 |
-
# word_tags.append(round(current_prob, 3))
|
148 |
-
# color = (
|
149 |
-
# "green" if current_prob < 0.25 else
|
150 |
-
# "yellow" if current_prob < 0.5 else
|
151 |
-
# "orange" if current_prob < 0.75 else
|
152 |
-
# "red"
|
153 |
-
# )
|
154 |
-
# color_output.append(f'<span style="color:{color}">{current_word}</span>')
|
155 |
-
|
156 |
-
# output = " ".join(color_output)
|
157 |
-
# return output, word_tags
|
158 |
-
|
159 |
-
|
160 |
# HF logging setup
|
161 |
def setup_hf_dataset():
|
162 |
global DATASET_CREATED
|
@@ -199,7 +152,13 @@ def infer_and_log(text_input):
|
|
199 |
except Exception as e:
|
200 |
print(f"Error uploading log: {e}")
|
201 |
|
202 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
|
204 |
def clear_fields():
|
205 |
return "", ""
|
@@ -213,7 +172,7 @@ with gr.Blocks() as app:
|
|
213 |
|
214 |
with gr.Row():
|
215 |
input_box = gr.Textbox(label="Input Text", lines=10)
|
216 |
-
output_box = gr.
|
217 |
|
218 |
with gr.Row():
|
219 |
submit_btn = gr.Button("Submit")
|
|
|
110 |
word_probs = [float(p) for p in word_probs]
|
111 |
return word_probs, word_colors
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
# HF logging setup
|
114 |
def setup_hf_dataset():
|
115 |
global DATASET_CREATED
|
|
|
152 |
except Exception as e:
|
153 |
print(f"Error uploading log: {e}")
|
154 |
|
155 |
+
tokens = text_input.split()
|
156 |
+
formatted_output = " ".join(
|
157 |
+
f'<span style="color:{color}">{token}</span>' for token, color in zip(tokens, word_colors)
|
158 |
+
)
|
159 |
+
|
160 |
+
return formatted_output
|
161 |
+
|
162 |
|
163 |
def clear_fields():
|
164 |
return "", ""
|
|
|
172 |
|
173 |
with gr.Row():
|
174 |
input_box = gr.Textbox(label="Input Text", lines=10)
|
175 |
+
output_box = gr.HTML(label="Output Text")
|
176 |
|
177 |
with gr.Row():
|
178 |
submit_btn = gr.Button("Submit")
|