Spaces:
Running
on
Zero
Running
on
Zero
initial commit
Browse files- .gitignore +2 -0
- README.md +5 -5
- app.py +77 -0
- requirements.txt +3 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
/venv
|
2 |
+
/.idea
|
README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
---
|
2 |
-
title: FLUX.1
|
3 |
-
emoji:
|
4 |
colorFrom: yellow
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license:
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: FLUX.1 [Inpainting]
|
3 |
+
emoji: 🎨
|
4 |
colorFrom: yellow
|
5 |
+
colorTo: pink
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 4.40.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
license: mit
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import gradio as gr
|
3 |
+
from diffusers import FluxInpaintPipeline
|
4 |
+
|
5 |
+
MARKDOWN = """
|
6 |
+
# FLUX.1 Inpainting 🔥
|
7 |
+
"""
|
8 |
+
|
9 |
+
DEVICE = torch.device("cuda")
|
10 |
+
# DEVICE = torch.device("cpu")
|
11 |
+
|
12 |
+
pipe = FluxInpaintPipeline.from_pretrained(
|
13 |
+
"black-forest-labs/FLUX.1-schnell",
|
14 |
+
torch_dtype=torch.bfloat16)
|
15 |
+
pipe.to(DEVICE)
|
16 |
+
|
17 |
+
|
18 |
+
@spaces.GPU()
|
19 |
+
def process(input_image_editor, input_text, progress=gr.Progress(track_tqdm=True)):
|
20 |
+
if not input_text:
|
21 |
+
gr.Info("Please enter a text prompt.")
|
22 |
+
return None
|
23 |
+
|
24 |
+
image = input_image_editor['background']
|
25 |
+
mask_image = input_image_editor['layers'][0]
|
26 |
+
|
27 |
+
if not image:
|
28 |
+
gr.Info("Please upload an image.")
|
29 |
+
return None
|
30 |
+
|
31 |
+
if not mask_image:
|
32 |
+
gr.Info("Please draw a mask on the image.")
|
33 |
+
return None
|
34 |
+
|
35 |
+
generator = torch.Generator().manual_seed(42)
|
36 |
+
return pipe(
|
37 |
+
prompt=input_text,
|
38 |
+
image=image,
|
39 |
+
mask_image=mask_image,
|
40 |
+
width=1024,
|
41 |
+
height=1024,
|
42 |
+
strength=0.9
|
43 |
+
).images[0]
|
44 |
+
|
45 |
+
|
46 |
+
with gr.Blocks() as demo:
|
47 |
+
gr.Markdown(MARKDOWN)
|
48 |
+
with gr.Row():
|
49 |
+
with gr.Column():
|
50 |
+
input_image_editor_component = gr.ImageEditor(
|
51 |
+
label='Image',
|
52 |
+
type='pil',
|
53 |
+
sources=["upload", "webcam"],
|
54 |
+
image_mode='RGB',
|
55 |
+
layers=False,
|
56 |
+
brush=gr.Brush(colors=["#000000"], color_mode="fixed"))
|
57 |
+
input_text_component = gr.Textbox(
|
58 |
+
label='Text prompt',
|
59 |
+
placeholder='Cartoon cactus',)
|
60 |
+
submit_button_component = gr.Button(
|
61 |
+
value='Submit', variant='primary')
|
62 |
+
with gr.Column():
|
63 |
+
output_image_component = gr.Image(
|
64 |
+
type='pil', image_mode='RGB', label='Generated image')
|
65 |
+
|
66 |
+
submit_button_component.click(
|
67 |
+
fn=process,
|
68 |
+
inputs=[
|
69 |
+
input_image_editor_component,
|
70 |
+
input_text_component
|
71 |
+
],
|
72 |
+
outputs=[
|
73 |
+
output_image_component
|
74 |
+
]
|
75 |
+
)
|
76 |
+
|
77 |
+
demo.launch(debug=False, show_error=True)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
spaces
|
3 |
+
git+https://github.com/Gothos/diffusers.git@flux-inpaint
|