TejAndrewsACC commited on
Commit
35c809f
·
verified ·
1 Parent(s): 83560a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -20
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import threading
2
  import time
3
- import random
4
  import os
5
  import gradio as gr
6
  from huggingface_hub import InferenceClient
@@ -11,31 +10,23 @@ client = InferenceClient(
11
  api_key=os.environ["HF_TOKEN"],
12
  )
13
 
14
- def run_edit(input_image, prompt, progress=gr.Progress()):
15
  stop_flag = {"stop": False}
16
 
17
  # --- background thread for smooth progress bar ---
18
  def progress_loop():
19
- start = time.time()
20
  current = 0.0
21
- total_time_guess = 10 # seconds, adjust to your model latency
22
 
23
  while not stop_flag["stop"]:
24
- elapsed = time.time() - start
25
-
26
- # Time-shaped curve approaching 99%
27
- target = min(0.99, (elapsed / total_time_guess) ** 0.7)
28
-
29
- # Smoothly move toward target
30
- current = current * 0.8 + target * 0.2
31
-
32
- progress(current, desc=f"Editing Image… {int(current*100)}%")
33
  time.sleep(0.05)
34
 
35
- # Finish immediately when model is done
36
- progress(1.0, desc="Done!")
37
 
38
- # Start progress bar thread
39
  thread = threading.Thread(target=progress_loop)
40
  thread.start()
41
 
@@ -46,7 +37,6 @@ def run_edit(input_image, prompt, progress=gr.Progress()):
46
  model="Qwen/Qwen-Image-Edit",
47
  )
48
 
49
- # Signal progress bar to finish
50
  stop_flag["stop"] = True
51
  thread.join()
52
 
@@ -62,15 +52,29 @@ with gr.Blocks(theme="TejAndrewsACC/ACC", title="Image Edit Demo") as demo:
62
 
63
  prompt = gr.Textbox(
64
  label="How do you want the image to be changed?",
65
- value="..."
66
  )
67
 
 
 
68
  run_btn = gr.Button("Run Edit")
69
 
70
  run_btn.click(
71
  fn=run_edit,
72
- inputs=[input_img, prompt],
73
  outputs=[output_img],
74
  )
75
 
76
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import threading
2
  import time
 
3
  import os
4
  import gradio as gr
5
  from huggingface_hub import InferenceClient
 
10
  api_key=os.environ["HF_TOKEN"],
11
  )
12
 
13
+ def run_edit(input_image, prompt, progress_bar):
14
  stop_flag = {"stop": False}
15
 
16
  # --- background thread for smooth progress bar ---
17
  def progress_loop():
 
18
  current = 0.0
19
+ total_time_guess = 10 # seconds, adjust to typical inference
20
 
21
  while not stop_flag["stop"]:
22
+ # Smooth progress approach
23
+ current += (0.99 - current) * 0.02
24
+ progress_bar.update(value=current, label=f"Editing Image… {int(current*100)}%")
 
 
 
 
 
 
25
  time.sleep(0.05)
26
 
27
+ # Finish immediately
28
+ progress_bar.update(value=1.0, label="Done!")
29
 
 
30
  thread = threading.Thread(target=progress_loop)
31
  thread.start()
32
 
 
37
  model="Qwen/Qwen-Image-Edit",
38
  )
39
 
 
40
  stop_flag["stop"] = True
41
  thread.join()
42
 
 
52
 
53
  prompt = gr.Textbox(
54
  label="How do you want the image to be changed?",
55
+ value="" # empty placeholder
56
  )
57
 
58
+ progress_bar = gr.Progress(label="Editing Image…", value=0.0)
59
+
60
  run_btn = gr.Button("Run Edit")
61
 
62
  run_btn.click(
63
  fn=run_edit,
64
+ inputs=[input_img, prompt, progress_bar],
65
  outputs=[output_img],
66
  )
67
 
68
+ # Optional CSS styling for the progress bar
69
+ custom_css = """
70
+ #component-3 .gradio-progress-bar {
71
+ height: 25px;
72
+ border-radius: 12px;
73
+ background-color: #e0e0e0;
74
+ }
75
+ #component-3 .gradio-progress-bar-fill {
76
+ background-color: #4CAF50;
77
+ transition: width 0.05s linear;
78
+ }
79
+ """
80
+ demo.launch(share=True, inline=False, css=custom_css)