AI-Image-Editor / app.py
TejAndrewsACC's picture
Update app.py
b2e7a1d verified
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()