pikapool1994 commited on
Commit
97eed01
·
1 Parent(s): 5a33c26

Add FLUX Kontext image editor

Browse files
Files changed (3) hide show
  1. README.md +7 -7
  2. app.py +92 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,15 +1,15 @@
1
  ---
2
  title: Image Editor Fast
3
- emoji: 🏢
4
- colorFrom: green
5
- colorTo: green
6
  sdk: gradio
7
- sdk_version: 6.14.0
8
- python_version: '3.13'
9
  app_file: app.py
10
  pinned: false
11
  license: openrail
12
- short_description: Image Editor Fast Prompt
13
  ---
14
 
15
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
  ---
2
  title: Image Editor Fast
3
+ emoji:
4
+ colorFrom: purple
5
+ colorTo: pink
6
  sdk: gradio
7
+ sdk_version: 6.0.0
 
8
  app_file: app.py
9
  pinned: false
10
  license: openrail
 
11
  ---
12
 
13
+ # FLUX.1 Kontext Image Editor
14
+
15
+ Edit images using natural language. Bring your own HF token.
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+ import gradio as gr
3
+ from huggingface_hub import InferenceClient
4
+ from PIL import Image
5
+
6
+ def edit_image(hf_token, input_image, prompt, progress=gr.Progress()):
7
+ if not hf_token.strip():
8
+ return None, "Please enter your HF token."
9
+ if input_image is None:
10
+ return None, "Please upload an image."
11
+ if not prompt.strip():
12
+ return None, "Please enter an edit instruction."
13
+
14
+ try:
15
+ client = InferenceClient(
16
+ provider="fal-ai",
17
+ api_key=hf_token.strip(),
18
+ )
19
+
20
+ progress(0.2, desc="Uploading image...")
21
+ img_bytes = io.BytesIO()
22
+ input_image.save(img_bytes, format="PNG")
23
+ img_bytes = img_bytes.getvalue()
24
+
25
+ progress(0.4, desc="Running FLUX Kontext...")
26
+ result = client.image_to_image(
27
+ img_bytes,
28
+ prompt=prompt.strip(),
29
+ model="black-forest-labs/FLUX.1-Kontext-dev",
30
+ )
31
+
32
+ progress(1.0, desc="Done!")
33
+ return result, "Done!"
34
+
35
+ except Exception as e:
36
+ return None, f"Error: {str(e)}"
37
+
38
+ EXAMPLES = [
39
+ ["Make the sky look like a sunset"],
40
+ ["Remove the background and make it white"],
41
+ ["Make it look like a watercolor painting"],
42
+ ["Add snow to the ground"],
43
+ ["Change the style to anime"],
44
+ ["Make it look like it was taken at night"],
45
+ ]
46
+
47
+ with gr.Blocks(title="FLUX Kontext Image Editor") as demo:
48
+ gr.Markdown("# FLUX.1 Kontext Image Editor")
49
+ gr.Markdown("Edit any image using natural language. Uses your own HF token — your credits, your privacy.")
50
+
51
+ with gr.Accordion("Setup: Enter your HF Token", open=True):
52
+ gr.Markdown("""
53
+ 1. Get your free token at [huggingface.co/settings/tokens](https://huggingface.co/settings/tokens)
54
+ 2. Make sure **Inference Providers** permission is enabled
55
+ 3. Paste it below — it stays in your browser only
56
+ """)
57
+ hf_token = gr.Textbox(
58
+ label="HF Token",
59
+ placeholder="hf_...",
60
+ type="password",
61
+ )
62
+
63
+ with gr.Row():
64
+ with gr.Column():
65
+ input_img = gr.Image(type="pil", label="Input Image")
66
+ prompt = gr.Textbox(
67
+ label="Edit Instruction",
68
+ placeholder="e.g. make the sky look like a sunset",
69
+ lines=2,
70
+ )
71
+ run_btn = gr.Button("Edit Image", variant="primary")
72
+ gr.Examples(examples=EXAMPLES, inputs=[prompt], label="Example Prompts")
73
+ with gr.Column():
74
+ output_img = gr.Image(label="Edited Image")
75
+ status = gr.Textbox(label="Status", interactive=False)
76
+
77
+ run_btn.click(
78
+ fn=edit_image,
79
+ inputs=[hf_token, input_img, prompt],
80
+ outputs=[output_img, status],
81
+ )
82
+
83
+ gr.Markdown("""
84
+ ### Tips
85
+ - Be specific: "make the sky orange and purple at sunset"
86
+ - Object removal: "remove the car on the left and fill with grass"
87
+ - Style: "make it look like a Van Gogh painting"
88
+ - Your HF token is never stored or sent anywhere except HF servers
89
+ """)
90
+
91
+ if __name__ == "__main__":
92
+ demo.launch(share=False)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ huggingface_hub
3
+ Pillow