IronJayx commited on
Commit
d3d6406
1 Parent(s): 7813680

require user to be logged in

Browse files
Files changed (3) hide show
  1. README.md +1 -0
  2. app.py +29 -0
  3. requirements.txt +2 -1
README.md CHANGED
@@ -11,6 +11,7 @@ short_description: Clean your room with the help of AI
11
  tags:
12
  - inpainting
13
  - image-to-image
 
14
  ---
15
 
16
  # Room Cleaner
 
11
  tags:
12
  - inpainting
13
  - image-to-image
14
+ hf_oauth: true
15
  ---
16
 
17
  # Room Cleaner
app.py CHANGED
@@ -12,6 +12,7 @@ from io import BytesIO
12
  import base64
13
  import numpy as np
14
 
 
15
  dotenv.load_dotenv()
16
 
17
 
@@ -36,6 +37,7 @@ def get_base64_from_image(image: Image.Image) -> str:
36
  def process_image(
37
  image: Image.Image | str | None,
38
  mask: Image.Image | str | None,
 
39
  progress: gr.Progress = gr.Progress(),
40
  ) -> Image.Image | None:
41
  progress(0, desc="Preparing inputs...")
@@ -54,6 +56,12 @@ def process_image(
54
  inputs: dict = {
55
  "image": f"data:image/png;base64,{image_base64}",
56
  "mask": f"data:image/png;base64,{mask_base64}",
 
 
 
 
 
 
57
  }
58
 
59
  # Call ComfyDeploy API
@@ -139,14 +147,32 @@ def resize_image(img: Image.Image, min_side_length: int = 768) -> Image.Image:
139
  return img.resize((new_width, min_side_length))
140
 
141
 
 
 
 
 
 
 
 
 
142
  async def process(
143
  image_and_mask: EditorValue | None,
144
  progress: gr.Progress = gr.Progress(),
 
145
  ) -> tuple[Image.Image, Image.Image] | None:
146
  if not image_and_mask:
147
  gr.Info("Please upload an image and draw a mask")
148
  return None
149
 
 
 
 
 
 
 
 
 
 
150
  image_np = image_and_mask["background"]
151
  image_np = cast(np.ndarray, image_np)
152
 
@@ -173,6 +199,7 @@ async def process(
173
  output = process_image(
174
  image, # type: ignore
175
  mask, # type: ignore
 
176
  progress,
177
  )
178
 
@@ -236,6 +263,8 @@ with gr.Blocks() as demo:
236
  interactive=False,
237
  )
238
 
 
 
239
  process_btn = gr.ClearButton(
240
  value="Run",
241
  variant="primary",
 
12
  import base64
13
  import numpy as np
14
 
15
+
16
  dotenv.load_dotenv()
17
 
18
 
 
37
  def process_image(
38
  image: Image.Image | str | None,
39
  mask: Image.Image | str | None,
40
+ user_data: dict,
41
  progress: gr.Progress = gr.Progress(),
42
  ) -> Image.Image | None:
43
  progress(0, desc="Preparing inputs...")
 
56
  inputs: dict = {
57
  "image": f"data:image/png;base64,{image_base64}",
58
  "mask": f"data:image/png;base64,{mask_base64}",
59
+ # "run_metatada": str(
60
+ # {
61
+ # "source": "HF",
62
+ # "user": user_data,
63
+ # }
64
+ # ),
65
  }
66
 
67
  # Call ComfyDeploy API
 
147
  return img.resize((new_width, min_side_length))
148
 
149
 
150
+ def get_profile(profile) -> dict:
151
+ return {
152
+ "username": profile.username,
153
+ "profile": profile.profile,
154
+ "name": profile.name,
155
+ }
156
+
157
+
158
  async def process(
159
  image_and_mask: EditorValue | None,
160
  progress: gr.Progress = gr.Progress(),
161
+ profile: gr.OAuthProfile | None = None,
162
  ) -> tuple[Image.Image, Image.Image] | None:
163
  if not image_and_mask:
164
  gr.Info("Please upload an image and draw a mask")
165
  return None
166
 
167
+ if profile is None:
168
+ gr.Info("Please log in to process the image.")
169
+ return None
170
+
171
+ user_data = get_profile(profile)
172
+ print("--------- RUN ----------")
173
+ print(user_data)
174
+ print("--------- RUN ----------")
175
+
176
  image_np = image_and_mask["background"]
177
  image_np = cast(np.ndarray, image_np)
178
 
 
199
  output = process_image(
200
  image, # type: ignore
201
  mask, # type: ignore
202
+ user_data,
203
  progress,
204
  )
205
 
 
263
  interactive=False,
264
  )
265
 
266
+ login_button = gr.LoginButton(scale=8)
267
+
268
  process_btn = gr.ClearButton(
269
  value="Run",
270
  variant="primary",
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  comfydeploy==0.3.4
2
  gradio==4.44.0
3
  gradio_imageslider==0.0.20
4
- python-dotenv
 
 
1
  comfydeploy==0.3.4
2
  gradio==4.44.0
3
  gradio_imageslider==0.0.20
4
+ python-dotenv
5
+ gradio[oauth]