Spaces:
Sleeping
Sleeping
init
Browse files- .gitignore +6 -0
- app.py +102 -0
- demo_footer.html +3 -0
- demo_header.html +15 -0
- examples/00538245.jpg +0 -0
- examples/acc.jpg +0 -0
- examples/eye-close.jpg +0 -0
- requirements.txt +3 -0
- tools.html +10 -0
.gitignore
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
__pycache__
|
2 |
+
*.egg-info
|
3 |
+
.ipynb_checkpoints
|
4 |
+
dist
|
5 |
+
.gradio
|
6 |
+
build
|
app.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import spaces
|
2 |
+
import gradio as gr
|
3 |
+
import re
|
4 |
+
from PIL import Image,ImageFilter
|
5 |
+
|
6 |
+
import os
|
7 |
+
import numpy as np
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
def process_images(fg_image):
|
13 |
+
# I'm not sure when this happen maybe api calling
|
14 |
+
#return fg_image["background"],fg_image['layers'][0]
|
15 |
+
def white_non_black(image):
|
16 |
+
return np.where(image > 0, 255, image)
|
17 |
+
|
18 |
+
mask = fg_image['layers'][0]
|
19 |
+
mask = mask.convert("L")
|
20 |
+
white_mask = Image.fromarray(white_non_black(np.array(mask)))
|
21 |
+
fg_image["background"].paste(fg_image['layers'][0], (0, 0),white_mask)
|
22 |
+
|
23 |
+
paint_masked = Image.composite(fg_image['layers'][0], Image.new("RGBA", fg_image['layers'][0].size, (0, 0, 0, 0)), white_mask)
|
24 |
+
|
25 |
+
return fg_image["background"],white_mask
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
def read_file(path: str) -> str:
|
30 |
+
with open(path, 'r', encoding='utf-8') as f:
|
31 |
+
content = f.read()
|
32 |
+
|
33 |
+
return content
|
34 |
+
|
35 |
+
css="""
|
36 |
+
#col-left {
|
37 |
+
margin: 0 auto;
|
38 |
+
max-width: 640px;
|
39 |
+
}
|
40 |
+
#col-right {
|
41 |
+
margin: 0 auto;
|
42 |
+
max-width: 640px;
|
43 |
+
}
|
44 |
+
.grid-container {
|
45 |
+
display: flex;
|
46 |
+
align-items: center;
|
47 |
+
justify-content: center;
|
48 |
+
gap:10px
|
49 |
+
}
|
50 |
+
|
51 |
+
.image {
|
52 |
+
width: 128px;
|
53 |
+
height: 128px;
|
54 |
+
object-fit: cover;
|
55 |
+
}
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
.text {
|
60 |
+
font-size: 16px;
|
61 |
+
}
|
62 |
+
"""
|
63 |
+
|
64 |
+
def color_changed(color,dict):
|
65 |
+
#mode must be RGBA
|
66 |
+
editor = gr.ImageEditor(value=dict,height=800,sources=['upload','clipboard'],transforms=[],image_mode='RGBA', layers=False, elem_id="Foreground", type="pil", label="Foreground",brush=gr.Brush(colors=[color], color_mode="fixed"))
|
67 |
+
return editor
|
68 |
+
|
69 |
+
with gr.Blocks(css=css, elem_id="demo-container") as demo:
|
70 |
+
with gr.Column():
|
71 |
+
gr.HTML(read_file("demo_header.html"))
|
72 |
+
gr.HTML(read_file("tools.html"))
|
73 |
+
with gr.Row():
|
74 |
+
with gr.Column():
|
75 |
+
#mode must be RGBA
|
76 |
+
image = gr.ImageEditor(height=800,sources=['upload','clipboard'],transforms=[],image_mode='RGBA', layers=False, elem_id="Foreground", type="pil", label="Foreground",brush=gr.Brush(colors=["#888"], color_mode="fixed"))
|
77 |
+
pick=gr.ColorPicker(label="color",value="#888",info="ImageEditor color is broken,pick color from here.reselect paint-tool and draw.")
|
78 |
+
pick.change(fn=color_changed,inputs=[pick,image],outputs=[image])
|
79 |
+
|
80 |
+
|
81 |
+
btn = gr.Button("Apply Paint", elem_id="run_button",variant="primary")
|
82 |
+
|
83 |
+
with gr.Column():
|
84 |
+
image_out = gr.Image(sources=[],label="Output", elem_id="output-img",format="png")
|
85 |
+
mask_out = gr.Image(sources=[],label="Mask", elem_id="mask-img",format="jpg")
|
86 |
+
|
87 |
+
|
88 |
+
|
89 |
+
|
90 |
+
btn.click(fn=process_images, inputs=[image], outputs =[image_out,mask_out], api_name='infer')
|
91 |
+
gr.Examples(
|
92 |
+
examples=[
|
93 |
+
["examples/00538245.jpg"],
|
94 |
+
["examples/eye-close.jpg"],
|
95 |
+
["examples/acc.jpg"]
|
96 |
+
]
|
97 |
+
,
|
98 |
+
inputs=[image]
|
99 |
+
)
|
100 |
+
gr.HTML(read_file("demo_footer.html"))
|
101 |
+
|
102 |
+
demo.launch()
|
demo_footer.html
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
<div>
|
2 |
+
<P> Images are generated with <a href="https://huggingface.co/black-forest-labs/FLUX.1-schnell">FLUX.1-schnell</a> and licensed under <a href="http://www.apache.org/licenses/LICENSE-2.0">the Apache 2.0 License</a>
|
3 |
+
</div>
|
demo_header.html
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div style="text-align: center;">
|
2 |
+
<h1>
|
3 |
+
Gradio540 Tmp Paint(Alpha Test)
|
4 |
+
</h1>
|
5 |
+
<div class="grid-container">
|
6 |
+
<img src="https://akjava.github.io/AIDiagramChatWithVoice-FaceCharacter/webp/128/00031245_08_00006200.webp" alt="Flux.1-schnell-WebP3Frame-TalkingAnimation" class="image">
|
7 |
+
<p class="text">
|
8 |
+
WARNING:sometime drawing data will gone.Not good at Undo.you can't draw black(0,0,0)<br>
|
9 |
+
Good for classic inpaint border.(If it's possible use Gimp or other paint tools)<br>
|
10 |
+
Paintng good at adding accessories with Flux, using inpainting/img2img, but not great at faces or bodies(only close eyes seems work)<br>
|
11 |
+
This is one of My solution for gradio5.40 painting,I dont't know which old version gradio paint work.<br>
|
12 |
+
the BUG is <a href="https://github.com/gradio-app/gradio/issues/9066">this</a>.I hope it will fix soon<br>
|
13 |
+
</p>
|
14 |
+
</div>
|
15 |
+
</div>
|
examples/00538245.jpg
ADDED
![]() |
examples/acc.jpg
ADDED
![]() |
examples/eye-close.jpg
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
spaces
|
2 |
+
numpy
|
3 |
+
opencv-contrib-python
|
tools.html
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div style="text-align: center;">
|
2 |
+
<p><a href="https://huggingface.co/spaces/Akjava/godot-huggingface-chain">AI Diagram Chat with Voice/Face Character Making Tools</a></p>
|
3 |
+
<p><a href="https://huggingface.co/spaces/Akjava/WebPTalkHead">[WebP-3F-TH]</a>
|
4 |
+
<a href="https://huggingface.co/spaces/Akjava/flux1-schnell-mask-inpaint">[Flux1-Inpaint(GPU)]</a>
|
5 |
+
<a href="https://huggingface.co/spaces/Akjava/OpenCVInpaintCPU">[OpenCV-Inapint]</a>
|
6 |
+
<a href="https://huggingface.co/spaces/Akjava/Simple-Whitebalance-Image">[Whitebalance]</a>
|
7 |
+
<a href="https://huggingface.co/spaces/Akjava/Simple-Mask-Paste-Image">[Paste Image]</a>
|
8 |
+
<a href="https://huggingface.co/spaces/Akjava/gradio540-tmp-paint">[Paint Image(Alpha)]</a>
|
9 |
+
<a href=" https://huggingface.co/spaces/Akjava/WebP-Resize-Convert">[WebP Resize Convert]</a></p>
|
10 |
+
</div>
|