yeq6x commited on
Commit
1564a3d
1 Parent(s): 320761b
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
- # テスト用に、Base64データを返す
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
- # Base64からPILイメージに変換
30
- sotai_image = Image.open(io.BytesIO(base64.b64decode(sotai_image_data)))
31
- sketch_image = Image.open(io.BytesIO(base64.b64decode(sketch_image_data)))
32
- # 画像を合成
33
- mixed_image = Image.new('RGBA', sotai_image.size, (0, 0, 0, 0))
34
- opacity_mask1 = Image.new('L', sotai_image.size, int(opacity1 * 255))
35
- opacity_mask2 = Image.new('L', sotai_image.size, int(opacity2 * 255))
36
- mixed_image.paste(sotai_image, (0, 0), mask=opacity_mask1)
37
- mixed_image.paste(sketch_image, (0, 0), mask=opacity_mask2)
 
 
 
 
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
- original_input = [
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=original_input,
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-----\nMIIE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zpBPaLLgkommBc5qKqgtg8gniJJ8ddWZYAYCWsPMxJwSA\nf74uYbbgbQKBgQDZJOJTiWGpKVpRDmX7KS5ARLKiXoYzDc3pwFl/6NlsFrRgYxdT\n47uLVFp1Do+SqZr0F2tcT3bY8QFBqmuV3ZuOsONsnhZPiXUqrmSoLdOp3cKgpJEo\nDc+HD+uNo3niP7/BPn271xjMZfc0JyCwy9jhnOJaFwMSh0zH/mt0Rf9h3QKBgQC5\nMU8kzkfcQgRckTu9yocfg6MwCTiSrI2nEFLxmAIFdDn0XA8jJ4eLzOLfnR3h+0zM\nq4cFu5Rv/98y3IIF6IbFsLaviCiUXKj+wtyrNfio4U/og4At5LNmrulHrmczkeMH\nhdCOnw3mR2zrke8EfshSs0D+CdNJUlh9xWVO9FmpuQKBgAqCGUXvTKKrSTmQS3Cv\nwvndgkBrl21zeOkIpDKFdHhMYgVFSF5CS3FIoSnbZrakHrEDYItG+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

  • SHA256: 7726e928c076887c75907312eb27e20e8f881f6b6abae2078dd0f0c29e42f177
  • Pointer size: 132 Bytes
  • Size of remote file: 1.79 MB
images/sample12.png DELETED

Git LFS Details

  • SHA256: abfd5bfd23700b36f71058024d8ee8e8efc6a49c4ae9596185ee98f94ea76e78
  • Pointer size: 132 Bytes
  • Size of remote file: 1.47 MB
images/sample13.png DELETED

Git LFS Details

  • SHA256: 464f5e2e0b077c02e6e47a26e734c1a9139dc29307a9c1729648978e4ed14a4b
  • Pointer size: 132 Bytes
  • Size of remote file: 2.56 MB
images/sample14.png DELETED

Git LFS Details

  • SHA256: 52b0d936981a46d56ea24c32192110fded61f60e21b19a155197cc4ece54f711
  • Pointer size: 132 Bytes
  • Size of remote file: 4.7 MB
images/sample15.png DELETED

Git LFS Details

  • SHA256: 90a8a57ac198c49645e8b2f0f54ace170d005397bbf425959e29f194552ba653
  • Pointer size: 132 Bytes
  • Size of remote file: 1.32 MB
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

  • SHA256: 7a0f3f0869a8f401d0c958552b077da43a6d79f82cfcfbe6b4f11139399f4e38
  • Pointer size: 132 Bytes
  • Size of remote file: 3.61 MB
images/sample8.png DELETED

Git LFS Details

  • SHA256: c6748b6a9c33e54df45ca0e83721290ff51ef3ddfbb43b34f135df5028939303
  • Pointer size: 132 Bytes
  • Size of remote file: 1.4 MB
images/sample9.png DELETED

Git LFS Details

  • SHA256: 3cb1855fbee747ad40fb38a2d1a68db772d2ff68557468c06bd5d082dadfcc9b
  • Pointer size: 132 Bytes
  • Size of remote file: 1.14 MB
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>