TejAndrewsACC commited on
Commit
4b92e8e
·
verified ·
1 Parent(s): 35c809f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -21
app.py CHANGED
@@ -10,22 +10,32 @@ client = 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()
@@ -52,29 +62,17 @@ with gr.Blocks(theme="TejAndrewsACC/ACC", title="Image Edit Demo") as demo:
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)
 
10
  api_key=os.environ["HF_TOKEN"],
11
  )
12
 
13
+ def run_edit(input_image, prompt, progress_html):
14
  stop_flag = {"stop": False}
15
 
16
  # --- background thread for smooth progress bar ---
17
  def progress_loop():
18
  current = 0.0
 
 
19
  while not stop_flag["stop"]:
20
  # Smooth progress approach
21
  current += (0.99 - current) * 0.02
22
+ bar_html = f"""
23
+ <div style='width: 100%; background-color: #e0e0e0; border-radius: 12px;'>
24
+ <div style='width: {current*100:.1f}%; background-color: #4CAF50; height: 25px; border-radius: 12px; transition: width 0.05s linear;'></div>
25
+ </div>
26
+ <div style='margin-top: 5px;'>Editing Image… {int(current*100)}%</div>
27
+ """
28
+ progress_html.update(bar_html)
29
  time.sleep(0.05)
30
 
31
  # Finish immediately
32
+ bar_html = f"""
33
+ <div style='width: 100%; background-color: #e0e0e0; border-radius: 12px;'>
34
+ <div style='width: 100%; background-color: #4CAF50; height: 25px; border-radius: 12px;'></div>
35
+ </div>
36
+ <div style='margin-top: 5px;'>Done!</div>
37
+ """
38
+ progress_html.update(bar_html)
39
 
40
  thread = threading.Thread(target=progress_loop)
41
  thread.start()
 
62
 
63
  prompt = gr.Textbox(
64
  label="How do you want the image to be changed?",
65
+ value="" # empty by default
66
  )
67
 
68
+ progress_html = gr.HTML("<div style='width:100%; height:25px; background-color:#e0e0e0; border-radius:12px;'></div>")
69
 
70
  run_btn = gr.Button("Run Edit")
71
 
72
  run_btn.click(
73
  fn=run_edit,
74
+ inputs=[input_img, prompt, progress_html],
75
  outputs=[output_img],
76
  )
77
 
78
+ demo.launch()