Spaces:
Running
Running
fix-prediction-input-can-be-too-long
#123
by
ZeroCommand
- opened
app_text_classification.py
CHANGED
@@ -72,6 +72,7 @@ def get_demo():
|
|
72 |
with gr.Row():
|
73 |
validation_result = gr.HTML(visible=False)
|
74 |
with gr.Row():
|
|
|
75 |
example_prediction = gr.Label(label="Model Sample Prediction", visible=False)
|
76 |
|
77 |
with gr.Row():
|
@@ -148,6 +149,10 @@ def get_demo():
|
|
148 |
fn=get_related_datasets_from_leaderboard,
|
149 |
inputs=[model_id_input],
|
150 |
outputs=[dataset_id_input],
|
|
|
|
|
|
|
|
|
151 |
)
|
152 |
|
153 |
gr.on(
|
@@ -202,6 +207,7 @@ def get_demo():
|
|
202 |
example_btn,
|
203 |
first_line_ds,
|
204 |
validation_result,
|
|
|
205 |
example_prediction,
|
206 |
column_mapping_accordion,],
|
207 |
)
|
@@ -222,6 +228,7 @@ def get_demo():
|
|
222 |
],
|
223 |
outputs=[
|
224 |
validation_result,
|
|
|
225 |
example_prediction,
|
226 |
column_mapping_accordion,
|
227 |
run_btn,
|
|
|
72 |
with gr.Row():
|
73 |
validation_result = gr.HTML(visible=False)
|
74 |
with gr.Row():
|
75 |
+
example_input = gr.Textbox(label="Example Input", visible=False, interactive=False)
|
76 |
example_prediction = gr.Label(label="Model Sample Prediction", visible=False)
|
77 |
|
78 |
with gr.Row():
|
|
|
149 |
fn=get_related_datasets_from_leaderboard,
|
150 |
inputs=[model_id_input],
|
151 |
outputs=[dataset_id_input],
|
152 |
+
).then(
|
153 |
+
fn=check_dataset,
|
154 |
+
inputs=[dataset_id_input],
|
155 |
+
outputs=[dataset_config_input, dataset_split_input, loading_dataset_info],
|
156 |
)
|
157 |
|
158 |
gr.on(
|
|
|
207 |
example_btn,
|
208 |
first_line_ds,
|
209 |
validation_result,
|
210 |
+
example_input,
|
211 |
example_prediction,
|
212 |
column_mapping_accordion,],
|
213 |
)
|
|
|
228 |
],
|
229 |
outputs=[
|
230 |
validation_result,
|
231 |
+
example_input,
|
232 |
example_prediction,
|
233 |
column_mapping_accordion,
|
234 |
run_btn,
|
text_classification_ui_helpers.py
CHANGED
@@ -186,6 +186,7 @@ def precheck_model_ds_enable_example_btn(
|
|
186 |
gr.update(visible=False),
|
187 |
gr.update(visible=False),
|
188 |
gr.update(visible=False),
|
|
|
189 |
)
|
190 |
|
191 |
try:
|
@@ -198,7 +199,8 @@ def precheck_model_ds_enable_example_btn(
|
|
198 |
return (
|
199 |
gr.update(interactive=False),
|
200 |
gr.update(value=df, visible=True),
|
201 |
-
gr.update(visible=False),
|
|
|
202 |
gr.update(visible=False),
|
203 |
gr.update(visible=False),
|
204 |
)
|
@@ -211,6 +213,7 @@ def precheck_model_ds_enable_example_btn(
|
|
211 |
gr.update(visible=False),
|
212 |
gr.update(visible=False),
|
213 |
gr.update(visible=False),
|
|
|
214 |
)
|
215 |
|
216 |
return (
|
@@ -219,12 +222,14 @@ def precheck_model_ds_enable_example_btn(
|
|
219 |
gr.update(visible=False),
|
220 |
gr.update(visible=False),
|
221 |
gr.update(visible=False),
|
|
|
222 |
)
|
223 |
except Exception as e:
|
224 |
# Config or split wrong
|
225 |
logger.warn(f"Check your dataset {dataset_id} and config {dataset_config} on split {dataset_split}: {e}")
|
226 |
return (
|
227 |
-
gr.update(interactive=False),
|
|
|
228 |
gr.update(visible=False),
|
229 |
gr.update(visible=False),
|
230 |
gr.update(visible=False),
|
@@ -266,6 +271,7 @@ def align_columns_and_show_prediction(
|
|
266 |
|
267 |
if prediction_input is None or prediction_response is None:
|
268 |
return (
|
|
|
269 |
gr.update(visible=False),
|
270 |
gr.update(visible=False),
|
271 |
gr.update(visible=False, open=False),
|
@@ -276,6 +282,7 @@ def align_columns_and_show_prediction(
|
|
276 |
|
277 |
if isinstance(prediction_response, HuggingFaceInferenceAPIResponse):
|
278 |
return (
|
|
|
279 |
gr.update(visible=False),
|
280 |
gr.update(visible=False),
|
281 |
gr.update(visible=False, open=False),
|
@@ -293,6 +300,7 @@ def align_columns_and_show_prediction(
|
|
293 |
if not isinstance(ds_labels, list) or not isinstance(ds_features, list):
|
294 |
gr.Warning(CHECK_CONFIG_OR_SPLIT_RAW)
|
295 |
return (
|
|
|
296 |
gr.update(visible=False),
|
297 |
gr.update(visible=False),
|
298 |
gr.update(visible=False, open=False),
|
@@ -305,6 +313,7 @@ def align_columns_and_show_prediction(
|
|
305 |
return (
|
306 |
gr.update(value=UNMATCHED_MODEL_DATASET_STYLED_ERROR, visible=True),
|
307 |
gr.update(visible=False),
|
|
|
308 |
gr.update(visible=False, open=False),
|
309 |
gr.update(interactive=False),
|
310 |
"",
|
@@ -327,6 +336,7 @@ def align_columns_and_show_prediction(
|
|
327 |
return (
|
328 |
gr.update(value=MAPPING_STYLED_ERROR_WARNING, visible=True),
|
329 |
gr.update(visible=False),
|
|
|
330 |
gr.update(visible=True, open=True),
|
331 |
gr.update(interactive=(run_inference and inference_token != "")),
|
332 |
"",
|
@@ -335,7 +345,8 @@ def align_columns_and_show_prediction(
|
|
335 |
|
336 |
return (
|
337 |
gr.update(value=VALIDATED_MODEL_DATASET_STYLED, visible=True),
|
338 |
-
gr.update(value=
|
|
|
339 |
gr.update(visible=True, open=False),
|
340 |
gr.update(interactive=(run_inference and inference_token != "")),
|
341 |
"",
|
|
|
186 |
gr.update(visible=False),
|
187 |
gr.update(visible=False),
|
188 |
gr.update(visible=False),
|
189 |
+
gr.update(visible=False),
|
190 |
)
|
191 |
|
192 |
try:
|
|
|
199 |
return (
|
200 |
gr.update(interactive=False),
|
201 |
gr.update(value=df, visible=True),
|
202 |
+
gr.update(visible=False),
|
203 |
+
gr.update(visible=False),
|
204 |
gr.update(visible=False),
|
205 |
gr.update(visible=False),
|
206 |
)
|
|
|
213 |
gr.update(visible=False),
|
214 |
gr.update(visible=False),
|
215 |
gr.update(visible=False),
|
216 |
+
gr.update(visible=False),
|
217 |
)
|
218 |
|
219 |
return (
|
|
|
222 |
gr.update(visible=False),
|
223 |
gr.update(visible=False),
|
224 |
gr.update(visible=False),
|
225 |
+
gr.update(visible=False),
|
226 |
)
|
227 |
except Exception as e:
|
228 |
# Config or split wrong
|
229 |
logger.warn(f"Check your dataset {dataset_id} and config {dataset_config} on split {dataset_split}: {e}")
|
230 |
return (
|
231 |
+
gr.update(interactive=False),
|
232 |
+
gr.update(visible=False),
|
233 |
gr.update(visible=False),
|
234 |
gr.update(visible=False),
|
235 |
gr.update(visible=False),
|
|
|
271 |
|
272 |
if prediction_input is None or prediction_response is None:
|
273 |
return (
|
274 |
+
gr.update(visible=False),
|
275 |
gr.update(visible=False),
|
276 |
gr.update(visible=False),
|
277 |
gr.update(visible=False, open=False),
|
|
|
282 |
|
283 |
if isinstance(prediction_response, HuggingFaceInferenceAPIResponse):
|
284 |
return (
|
285 |
+
gr.update(visible=False),
|
286 |
gr.update(visible=False),
|
287 |
gr.update(visible=False),
|
288 |
gr.update(visible=False, open=False),
|
|
|
300 |
if not isinstance(ds_labels, list) or not isinstance(ds_features, list):
|
301 |
gr.Warning(CHECK_CONFIG_OR_SPLIT_RAW)
|
302 |
return (
|
303 |
+
gr.update(visible=False),
|
304 |
gr.update(visible=False),
|
305 |
gr.update(visible=False),
|
306 |
gr.update(visible=False, open=False),
|
|
|
313 |
return (
|
314 |
gr.update(value=UNMATCHED_MODEL_DATASET_STYLED_ERROR, visible=True),
|
315 |
gr.update(visible=False),
|
316 |
+
gr.update(visible=False),
|
317 |
gr.update(visible=False, open=False),
|
318 |
gr.update(interactive=False),
|
319 |
"",
|
|
|
336 |
return (
|
337 |
gr.update(value=MAPPING_STYLED_ERROR_WARNING, visible=True),
|
338 |
gr.update(visible=False),
|
339 |
+
gr.update(visible=False),
|
340 |
gr.update(visible=True, open=True),
|
341 |
gr.update(interactive=(run_inference and inference_token != "")),
|
342 |
"",
|
|
|
345 |
|
346 |
return (
|
347 |
gr.update(value=VALIDATED_MODEL_DATASET_STYLED, visible=True),
|
348 |
+
gr.update(value=prediction_input, lines=len(prediction_input)//225 + 1, visible=True),
|
349 |
+
gr.update(value=prediction_response, visible=True),
|
350 |
gr.update(visible=True, open=False),
|
351 |
gr.update(interactive=(run_inference and inference_token != "")),
|
352 |
"",
|