File size: 1,706 Bytes
b2e7a1d
 
0522ae1
b2e7a1d
0522ae1
 
 
b2e7a1d
0522ae1
 
 
 
 
b2e7a1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0522ae1
 
 
 
 
 
b2e7a1d
 
0522ae1
 
b2e7a1d
0522ae1
904e5fa
 
0522ae1
 
 
 
 
 
904e5fa
b2e7a1d
0522ae1
 
 
 
 
b2e7a1d
 
0522ae1
 
 
b2e7a1d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

import gradio as gr
import time
import random
import os
from huggingface_hub import InferenceClient

# Initialize client
client = InferenceClient(
    provider="fal-ai",
    api_key=os.environ["HF_TOKEN"],
)

def smooth_progress_bar():
    """
    Generates a smooth, natural-looking progress curve that slowly approaches 99%.
    """
    progress = gr.Progress(track_tqdm=False)

    current = 0.0
    while current < 0.99:
        # Small random increments for a natural feel
        increment = random.uniform(0.003, 0.007)  # ~0.3%–0.7%

        # Speed adjusts as we get closer to 99%
        delay = random.uniform(0.01, 0.03)

        current = min(0.99, current + increment)
        progress(current, desc=f"Editing image… {int(current*100)}%")

        time.sleep(delay)

    return progress


def run_edit(input_image, prompt):
    progress = smooth_progress_bar()

    # Real model call
    output = client.image_to_image(
        input_image,
        prompt=prompt,
        model="Qwen/Qwen-Image-Edit",
    )

    # Instantly finish
    progress(1.0, desc="Done!")
    return output


# --- Gradio UI ---
with gr.Blocks(theme="TejAndrewsACC/ACC", title="Image Edit Demo") as demo:
    gr.Markdown("## ACC AI Image Editor")

    with gr.Row():
        input_img = gr.Image(type="filepath", label="Upload Image")
        output_img = gr.Image(label="Edited Image")

    prompt = gr.Textbox(
        label="How do you want the image to be changed?",
        value=""
    )

    run_btn = gr.Button("Run Edit")

    run_btn.click(
        fn=lambda img_path, pr: run_edit(open(img_path, "rb").read(), pr),
        inputs=[input_img, prompt],
        outputs=[output_img],
    )

demo.launch()