yeq6x commited on
Commit
eca7532
1 Parent(s): fb6d090

firebase init

Browse files
app.py CHANGED
@@ -1,4 +1,7 @@
1
  import gradio as gr
 
 
 
2
  import os
3
  import io
4
  from PIL import Image
@@ -12,15 +15,53 @@ initialize(_use_local=False, use_gpu=True, use_dotenv=False)
12
  init_model(use_local=False)
13
  load_wd14_tagger_model()
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  def process_image(input_image, mode, weight1, weight2):
16
- # 画像処理ロジック
17
  sotai_image, sketch_image = process_image_as_base64(input_image, mode, weight1, weight2)
18
 
19
- # Base64文字列をPIL Imageに変換
20
- sotai_pil = Image.open(io.BytesIO(base64.b64decode(sotai_image)))
21
- sketch_pil = Image.open(io.BytesIO(base64.b64decode(sketch_image)))
22
 
23
- return sotai_pil, sketch_pil
24
 
25
  # Gradio インターフェースの定義
26
  iface = gr.Interface(
@@ -32,8 +73,8 @@ iface = gr.Interface(
32
  gr.Slider(0, 1, value=0.05, step=0.025, label="Weight 2 (Body)")
33
  ],
34
  outputs=[
35
- gr.Image(type="pil", label="Sotai (Body) Image"),
36
- gr.Image(type="pil", label="Sketch Image")
37
  ],
38
  title="Image2Body API",
39
  description="Upload an image and select processing options to generate body and sketch images."
 
1
  import gradio as gr
2
+ import firebase_admin
3
+ from firebase_admin import credentials, storage
4
+ import tempfile
5
  import os
6
  import io
7
  from PIL import Image
 
15
  init_model(use_local=False)
16
  load_wd14_tagger_model()
17
 
18
+ # Firebase の初期化
19
+ cred = credentials.Certificate("firebase/image2body-demo-firebase-adminsdk-ope1k-e19e1da82c.json")
20
+ firebase_admin.initialize_app(cred, {
21
+ 'storageBucket': 'image2body-demo.appspot.com'
22
+ })
23
+ def save_image_pair_to_firebase(sotai_image_data, sketch_image_data):
24
+ # 一意の識別子を生成
25
+ unique_id = str(uuid.uuid4())
26
+ timestamp = int(time.time())
27
+ folder_name = f"image_pairs/{timestamp}_{unique_id}"
28
+
29
+ # Base64 データを PIL Image に変換
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
+ bucket = storage.bucket()
34
+ urls = {}
35
+
36
+ for image_type, image in [("sotai", sotai_image), ("sketch", sketch_image)]:
37
+ # 一時ファイルを作成
38
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file:
39
+ image.save(temp_file, format="PNG")
40
+ temp_file_path = temp_file.name
41
+
42
+ try:
43
+ # Firebase Storage にアップロード
44
+ blob_path = f'{folder_name}/{image_type}.png'
45
+ blob = bucket.blob(blob_path)
46
+ blob.upload_from_filename(temp_file_path)
47
+
48
+ # URLを取得
49
+ blob.make_public()
50
+ urls[image_type] = blob.public_url
51
+ finally:
52
+ # 一時ファイルを削除
53
+ os.unlink(temp_file_path)
54
+
55
+ return urls
56
+
57
  def process_image(input_image, mode, weight1, weight2):
58
+ # 既存の画像処理ロジック
59
  sotai_image, sketch_image = process_image_as_base64(input_image, mode, weight1, weight2)
60
 
61
+ # Firebase に画像ペアを保存し、URLを取得
62
+ urls = save_image_pair_to_firebase(sotai_image, sketch_image)
 
63
 
64
+ return urls['sotai'], urls['sketch']
65
 
66
  # Gradio インターフェースの定義
67
  iface = gr.Interface(
 
73
  gr.Slider(0, 1, value=0.05, step=0.025, label="Weight 2 (Body)")
74
  ],
75
  outputs=[
76
+ gr.Text(label="Sotai Image URL"),
77
+ gr.Text(label="Sketch Image URL")
78
  ],
79
  title="Image2Body API",
80
  description="Upload an image and select processing options to generate body and sketch images."
firebase/image2body-demo-firebase-adminsdk-ope1k-e19e1da82c.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "type": "service_account",
3
+ "project_id": "image2body-demo",
4
+ "private_key_id": "e19e1da82c39206ae07a42271eb6e9a067b501b6",
5
+ "private_key": "-----BEGIN P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og31YTb+Dm1SnbvxzzpBPaLLgkommBc5qKqgtg8gniJJ8ddWZYAYCWsPMxJwSA\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
+ }
requirements.txt CHANGED
@@ -22,4 +22,5 @@ python-dotenv
22
  peft==0.11.1
23
  flask_limiter==3.7.0
24
  gevent==24.2.1
25
- gevent-websocket==0.10.1
 
 
22
  peft==0.11.1
23
  flask_limiter==3.7.0
24
  gevent==24.2.1
25
+ gevent-websocket==0.10.1
26
+ firebase-admin