Spaces:
Running
on
Zero
Running
on
Zero
del
Browse files- app.py +25 -45
- firebase/image2body-demo-firebase-adminsdk-ope1k-e19e1da82c.json +0 -13
- images/sample11.png +0 -3
- images/sample12.png +0 -3
- images/sample13.png +0 -3
- images/sample14.png +0 -3
- images/sample15.png +0 -3
- images/sample17.png +0 -0
- images/sample20.png +0 -0
- images/sample21.png +0 -0
- images/sample3.png +0 -3
- images/sample8.png +0 -3
- images/sample9.png +0 -3
- templates/index.html +0 -12
app.py
CHANGED
@@ -19,22 +19,22 @@ def process_image(input_image, mode, weight1=None, weight2=None):
|
|
19 |
elif mode == "refine":
|
20 |
sotai_image, sketch_image = process_image_as_base64(input_image, mode, weight1, weight2)
|
21 |
|
22 |
-
|
23 |
-
sotai_image = image_to_base64(input_image)
|
24 |
-
sketch_image = image_to_base64(input_image)
|
25 |
-
|
26 |
-
return sotai_image, sketch_image
|
27 |
|
28 |
def mix_images(sotai_image_data, sketch_image_data, opacity1, opacity2):
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
38 |
|
39 |
return mixed_image
|
40 |
|
@@ -47,20 +47,21 @@ with gr.Blocks() as demo:
|
|
47 |
submit = None
|
48 |
with gr.Row():
|
49 |
with gr.Column() as input_col:
|
|
|
50 |
with gr.Tab("original"):
|
51 |
-
|
52 |
-
gr.Image(type="pil", label="Input Image"),
|
53 |
-
gr.Text("original", label="Mode", visible=False),
|
54 |
-
]
|
55 |
original_submit = gr.Button("Submit", variant="primary")
|
56 |
with gr.Tab("refine"):
|
57 |
refine_input = [
|
58 |
-
gr.Image(type="pil", label="Input Image"),
|
59 |
gr.Text("refine", label="Mode", visible=False),
|
60 |
gr.Slider(0, 2, value=0.6, step=0.05, label="Weight 1 (Sketch)"),
|
61 |
gr.Slider(0, 1, value=0.05, step=0.025, label="Weight 2 (Body)")
|
62 |
]
|
63 |
refine_submit = gr.Button("Submit", variant="primary")
|
|
|
|
|
|
|
|
|
64 |
with gr.Column() as output_col:
|
65 |
sotai_image_data = gr.Text(label="Sotai Image data", visible=False)
|
66 |
sketch_image_data = gr.Text(label="Sketch Image data", visible=False)
|
@@ -70,13 +71,13 @@ with gr.Blocks() as demo:
|
|
70 |
|
71 |
original_submit.click(
|
72 |
process_image,
|
73 |
-
inputs=
|
74 |
-
outputs=[sotai_image_data, sketch_image_data]
|
75 |
)
|
76 |
refine_submit.click(
|
77 |
process_image,
|
78 |
-
inputs=refine_input,
|
79 |
-
outputs=[sotai_image_data, sketch_image_data]
|
80 |
)
|
81 |
sotai_image_data.change(
|
82 |
mix_images,
|
@@ -94,25 +95,4 @@ with gr.Blocks() as demo:
|
|
94 |
outputs=mixed_image
|
95 |
)
|
96 |
|
97 |
-
demo.launch()
|
98 |
-
|
99 |
-
|
100 |
-
# # Gradio インターフェースの定義
|
101 |
-
# iface = gr.Interface(
|
102 |
-
# fn=process_image,
|
103 |
-
# inputs=[
|
104 |
-
# gr.Image(type="pil", label="Input Image"),
|
105 |
-
# gr.Radio(["original", "refine"], label="Mode", value="original"),
|
106 |
-
# gr.Slider(0, 2, value=0.6, step=0.05, label="Weight 1 (Sketch)"),
|
107 |
-
# gr.Slider(0, 1, value=0.05, step=0.025, label="Weight 2 (Body)")
|
108 |
-
# ],
|
109 |
-
# outputs=[
|
110 |
-
# gr.Text(label="Sotai Image URL"),
|
111 |
-
# gr.Text(label="Sketch Image URL")
|
112 |
-
# ],
|
113 |
-
# title="Image2Body API",
|
114 |
-
# description="Upload an image and select processing options to generate body and sketch images."
|
115 |
-
# )
|
116 |
-
|
117 |
-
# # Hugging Face Spacesでデプロイする場合
|
118 |
-
# iface.queue().launch()
|
|
|
19 |
elif mode == "refine":
|
20 |
sotai_image, sketch_image = process_image_as_base64(input_image, mode, weight1, weight2)
|
21 |
|
22 |
+
return sotai_image, sketch_image, None
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def mix_images(sotai_image_data, sketch_image_data, opacity1, opacity2):
|
25 |
+
sotai_image = Image.open(io.BytesIO(base64.b64decode(sotai_image_data))).convert('RGBA')
|
26 |
+
sketch_image = Image.open(io.BytesIO(base64.b64decode(sketch_image_data))).convert('RGBA')
|
27 |
+
|
28 |
+
if sotai_image.size != sketch_image.size:
|
29 |
+
sketch_image = sketch_image.resize(sotai_image.size, Image.Resampling.LANCZOS)
|
30 |
+
|
31 |
+
mixed_image = Image.new('RGBA', sotai_image.size, (255, 255, 255, 255))
|
32 |
+
|
33 |
+
sotai_alpha = sotai_image.getchannel('A').point(lambda x: int(x * opacity1))
|
34 |
+
sketch_alpha = sketch_image.getchannel('A').point(lambda x: int(x * opacity2))
|
35 |
+
|
36 |
+
mixed_image.paste(sketch_image, (0, 0), mask=sketch_alpha)
|
37 |
+
mixed_image.paste(sotai_image, (0, 0), mask=sotai_alpha)
|
38 |
|
39 |
return mixed_image
|
40 |
|
|
|
47 |
submit = None
|
48 |
with gr.Row():
|
49 |
with gr.Column() as input_col:
|
50 |
+
input_image = gr.Image(type="pil", label="Input Image")
|
51 |
with gr.Tab("original"):
|
52 |
+
original_mode = gr.Text("original", label="Mode", visible=False)
|
|
|
|
|
|
|
53 |
original_submit = gr.Button("Submit", variant="primary")
|
54 |
with gr.Tab("refine"):
|
55 |
refine_input = [
|
|
|
56 |
gr.Text("refine", label="Mode", visible=False),
|
57 |
gr.Slider(0, 2, value=0.6, step=0.05, label="Weight 1 (Sketch)"),
|
58 |
gr.Slider(0, 1, value=0.05, step=0.025, label="Weight 2 (Body)")
|
59 |
]
|
60 |
refine_submit = gr.Button("Submit", variant="primary")
|
61 |
+
gr.Examples(
|
62 |
+
examples=[f"images/sample{i}.png" for i in [1, 2, 4, 5, 6, 7, 10, 16, 18, 19]],
|
63 |
+
inputs=[input_image]
|
64 |
+
)
|
65 |
with gr.Column() as output_col:
|
66 |
sotai_image_data = gr.Text(label="Sotai Image data", visible=False)
|
67 |
sketch_image_data = gr.Text(label="Sketch Image data", visible=False)
|
|
|
71 |
|
72 |
original_submit.click(
|
73 |
process_image,
|
74 |
+
inputs=[input_image, original_mode],
|
75 |
+
outputs=[sotai_image_data, sketch_image_data, mixed_image]
|
76 |
)
|
77 |
refine_submit.click(
|
78 |
process_image,
|
79 |
+
inputs=[input_image, refine_input[0], refine_input[1], refine_input[2]],
|
80 |
+
outputs=[sotai_image_data, sketch_image_data, mixed_image]
|
81 |
)
|
82 |
sotai_image_data.change(
|
83 |
mix_images,
|
|
|
95 |
outputs=mixed_image
|
96 |
)
|
97 |
|
98 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
firebase/image2body-demo-firebase-adminsdk-ope1k-e19e1da82c.json
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"type": "service_account",
|
3 |
-
"project_id": "image2body-demo",
|
4 |
-
"private_key_id": "e19e1da82c39206ae07a42271eb6e9a067b501b6",
|
5 |
-
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDp/N0pO3GUp5/k\nKvzNRBrmN8EgPwqDT+SeQYWn8po+xmtWUcrLlUH1ZgRTaJvkdgxxSsGfoOSj1mjw\nVSYudfT7763PTznqHWi7ShHvLwriuoEaJkwN4yhLyayTR42AQelPJUkl0FvE/DO7\neVjYtbReXH5+lSFjTYK7/Z0mS1D5Bc3ubEUDjJb0/ySc+i4Q/hmy+RiwDwkpTDPu\nufMUgcGHvv1ApMiwqXQMv2OuBigW1XS+IpNhwmTP5c7DlwnFm8qaVnwQcaj9NbPW\nNP2wrEjkzo2piY33GZ+dTV7wwAdJLjY30dKcEdkrcRU0dhDOZ++hwhGB4hecGnlR\nHbrS58AbAgMBAAECggEARC8g3WaKkwiDsdALCd+6PPLrTrPAIwKxeqJaSdYKt5dH\naQh9oXSVm2aGhS27G8iAmLTxl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3FIoSnbZrakHrEDYItG+UjVepH9kvmn\nk4KPZJ4CzO3qwnKIdc28kSfT1tK3GDC3aufh9ucWuGSfHO7j6D7yM73Lb/FsRpju\nA8nojFAbWcfdKpCjh1xiRDTF\n-----END PRIVATE KEY-----\n",
|
6 |
-
"client_email": "firebase-adminsdk-ope1k@image2body-demo.iam.gserviceaccount.com",
|
7 |
-
"client_id": "105880637239614588319",
|
8 |
-
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
9 |
-
"token_uri": "https://oauth2.googleapis.com/token",
|
10 |
-
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
11 |
-
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-ope1k%40image2body-demo.iam.gserviceaccount.com",
|
12 |
-
"universe_domain": "googleapis.com"
|
13 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
images/sample11.png
DELETED
Git LFS Details
|
images/sample12.png
DELETED
Git LFS Details
|
images/sample13.png
DELETED
Git LFS Details
|
images/sample14.png
DELETED
Git LFS Details
|
images/sample15.png
DELETED
Git LFS Details
|
images/sample17.png
DELETED
Binary file (450 kB)
|
|
images/sample20.png
DELETED
Binary file (894 kB)
|
|
images/sample21.png
DELETED
Binary file (748 kB)
|
|
images/sample3.png
DELETED
Git LFS Details
|
images/sample8.png
DELETED
Git LFS Details
|
images/sample9.png
DELETED
Git LFS Details
|
templates/index.html
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html lang="en">
|
3 |
-
<head>
|
4 |
-
<meta charset="UTF-8">
|
5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>{{ title }}</title>
|
7 |
-
</head>
|
8 |
-
<body>
|
9 |
-
<h1>Welcome to our website</h1>
|
10 |
-
<p>This is the home page rendered using a Flask template.</p>
|
11 |
-
</body>
|
12 |
-
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|