Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,78 +1,24 @@
|
|
1 |
import gradio as gr
|
2 |
-
import time
|
3 |
-
|
4 |
-
MAX_NON_INT_ITERATIONS = 5
|
5 |
-
|
6 |
-
def test_loop_function(iterations_count, text_param, progress=gr.Progress()):
|
7 |
-
print(f"\n--- test_loop_function CALLED ---")
|
8 |
-
print(f"Expected iterations_count: {iterations_count} (type: {type(iterations_count)})")
|
9 |
-
print(f"text_param: '{text_param}' (type: {type(text_param)})")
|
10 |
-
print(f"Progress object received: {progress} (type: {type(progress)})")
|
11 |
-
|
12 |
-
log_messages = [
|
13 |
-
f"Expected iterations: {iterations_count}",
|
14 |
-
f"Text param: {text_param}"
|
15 |
-
]
|
16 |
-
|
17 |
-
non_int_i_counter = 0
|
18 |
-
|
19 |
-
# The loop in question
|
20 |
-
for i in progress.tqdm(range(iterations_count), desc="Processing..."):
|
21 |
-
current_log = f"Loop variable i = {i}, type(i) = {type(i)}"
|
22 |
-
print(current_log)
|
23 |
-
log_messages.append(current_log)
|
24 |
|
|
|
|
|
|
|
|
|
25 |
if not isinstance(i, int):
|
26 |
-
|
27 |
-
|
28 |
-
non_int_i_counter += 1
|
29 |
-
if non_int_i_counter >= MAX_NON_INT_ITERATIONS:
|
30 |
-
print(f"Breaking loop after {non_int_i_counter} non-integer 'i' values.")
|
31 |
-
log_messages.append("Breaking loop due to repeated non-integer 'i'.")
|
32 |
-
break
|
33 |
-
|
34 |
-
time.sleep(0.1)
|
35 |
-
|
36 |
-
final_message = "Loop finished."
|
37 |
-
if non_int_i_counter > 0 :
|
38 |
-
final_message = "Loop finished (or was broken) with non-integer 'i' issues."
|
39 |
-
|
40 |
-
print(final_message)
|
41 |
-
log_messages.append(final_message)
|
42 |
-
return "\n".join(log_messages)
|
43 |
|
44 |
with gr.Blocks() as demo:
|
45 |
-
gr.Markdown(
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
)
|
50 |
-
|
51 |
-
with gr.Row():
|
52 |
-
iterations_slider = gr.Slider(minimum=1, maximum=10, value=3, step=1, label="Number of Iterations")
|
53 |
-
dummy_text = gr.Textbox(label="Dummy Text Parameter", value="Test")
|
54 |
-
|
55 |
-
output_log = gr.Textbox(label="Function Log Output", lines=15, interactive=False)
|
56 |
-
|
57 |
-
run_button = gr.Button()
|
58 |
-
run_button.click(
|
59 |
-
fn=test_loop_function,
|
60 |
-
inputs=[iterations_slider, dummy_text],
|
61 |
-
outputs=[output_log]
|
62 |
-
)
|
63 |
|
64 |
gr.Examples(
|
65 |
-
examples=[
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
inputs=[iterations_slider, dummy_text],
|
70 |
-
outputs=[output_log],
|
71 |
-
fn=test_loop_function,
|
72 |
-
cache_examples="lazy"
|
73 |
)
|
74 |
-
|
75 |
-
gr.Markdown("Console output (printed by the function) will also show detailed logs.")
|
76 |
-
|
77 |
-
if __name__ == "__main__":
|
78 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
def func(iters, progress=gr.Progress()):
|
4 |
+
print(f"iters: {iters}, type: {type(iters)}")
|
5 |
+
for i in progress.tqdm(range(iters), desc="Looping"):
|
6 |
+
print(f"i: {i}, type: {type(i)}")
|
7 |
if not isinstance(i, int):
|
8 |
+
return f"BUG! i is {type(i)}"
|
9 |
+
return "OK"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
with gr.Blocks() as demo:
|
12 |
+
gr.Markdown("Bug Reproduction: `gr.Progress.tqdm` with `gr.Examples`\n")
|
13 |
+
iters_input = gr.Number(value=3, label="Iterations")
|
14 |
+
out = gr.Textbox(label="Output")
|
15 |
+
btn = gr.Button("Run Manually")
|
16 |
+
btn.click(func, [iters_input], out)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
gr.Examples(
|
19 |
+
examples=[[5], [2]],
|
20 |
+
inputs=[iters_input],
|
21 |
+
outputs=[out],
|
22 |
+
fn=func
|
|
|
|
|
|
|
|
|
23 |
)
|
24 |
+
demo.launch()
|
|
|
|
|
|
|
|