rynmurdock commited on
Commit
cb79844
2 Parent(s): 86d2837 383d2cb
Files changed (2) hide show
  1. app.py +1 -12
  2. safety_checker_improved.py +5 -4
app.py CHANGED
@@ -123,20 +123,11 @@ pipe.unet.fuse_qkv_projections()
123
  pipe.to(device=DEVICE)
124
  #pipe.unet = torch.compile(pipe.unet)
125
  #pipe.vae = torch.compile(pipe.vae)
126
- # TODO cannot compile on Spaces or we time out; don't run leave_imb stuff either
127
- #im_embs = torch.zeros(1, 1, 1, 1280, device=DEVICE, dtype=dtype)
128
- #output = pipe(prompt='a person', guidance_scale=0, added_cond_kwargs={}, ip_adapter_image_embeds=[im_embs], num_inference_steps=STEPS)
129
- #leave_im_emb, _ = pipe.encode_image(
130
- # output.frames[0][len(output.frames[0])//2], DEVICE, 1, output_hidden_state
131
- #)
132
- #assert len(output.frames[0]) == 16
133
- #leave_im_emb.detach().to('cpu')
134
 
135
  @spaces.GPU(duration=10)
136
  def generate_gpu(in_im_embs):
137
  print('start gen')
138
  in_im_embs = in_im_embs.to('cuda').unsqueeze(0).unsqueeze(0)
139
- #im_embs = torch.cat((torch.zeros(1, 1280, device=DEVICE, dtype=dtype), in_im_embs), 0)
140
 
141
  output = pipe(prompt='', guidance_scale=0, added_cond_kwargs={}, ip_adapter_image_embeds=[in_im_embs], num_inference_steps=STEPS)
142
  print('image is made')
@@ -148,7 +139,6 @@ def generate_gpu(in_im_embs):
148
  return output, im_emb
149
 
150
  def generate(in_im_embs):
151
-
152
  output, im_emb = generate_gpu(in_im_embs)
153
  nsfw = maybe_nsfw(output.frames[0][len(output.frames[0])//2])
154
 
@@ -358,8 +348,7 @@ def choose(img, choice, calibrate_prompts, user_id, request: gr.Request):
358
  choice = 0
359
 
360
  row_mask = [p.split('/')[-1] in img for p in prevs_df['paths'].to_list()]
361
-
362
-
363
  if len(prevs_df.loc[row_mask, 'user:rating']) > 0:
364
  prevs_df.loc[row_mask, 'user:rating'][0][user_id] = choice
365
  prevs_df.loc[row_mask, 'latest_user_to_rate'] = [user_id]
 
123
  pipe.to(device=DEVICE)
124
  #pipe.unet = torch.compile(pipe.unet)
125
  #pipe.vae = torch.compile(pipe.vae)
 
 
 
 
 
 
 
 
126
 
127
  @spaces.GPU(duration=10)
128
  def generate_gpu(in_im_embs):
129
  print('start gen')
130
  in_im_embs = in_im_embs.to('cuda').unsqueeze(0).unsqueeze(0)
 
131
 
132
  output = pipe(prompt='', guidance_scale=0, added_cond_kwargs={}, ip_adapter_image_embeds=[in_im_embs], num_inference_steps=STEPS)
133
  print('image is made')
 
139
  return output, im_emb
140
 
141
  def generate(in_im_embs):
 
142
  output, im_emb = generate_gpu(in_im_embs)
143
  nsfw = maybe_nsfw(output.frames[0][len(output.frames[0])//2])
144
 
 
348
  choice = 0
349
 
350
  row_mask = [p.split('/')[-1] in img for p in prevs_df['paths'].to_list()]
351
+ # if it's still in the dataframe, add the choice
 
352
  if len(prevs_df.loc[row_mask, 'user:rating']) > 0:
353
  prevs_df.loc[row_mask, 'user:rating'][0][user_id] = choice
354
  prevs_df.loc[row_mask, 'latest_user_to_rate'] = [user_id]
safety_checker_improved.py CHANGED
@@ -9,11 +9,12 @@ import sys
9
  sys.path.append('/home/ryn_mote/Misc/generative_recommender/gradio_video/automl/efficientnetv2/')
10
  import tensorflow as tf
11
  from tensorflow.keras import mixed_precision
12
- #physical_devices = tf.config.list_physical_devices('GPU')
13
 
14
- #tf.config.experimental.set_memory_growth(
15
- # physical_devices[0], True
16
- #)
 
 
17
 
18
  model = tf.keras.models.load_model('nsfweffnetv2-b02-3epochs.h5',custom_objects={"KerasLayer":hub.KerasLayer})
19
  # "The image classifier had been trained on 682550 images from the 5 classes "Drawing" (39026), "Hentai" (28134), "Neutral" (369507), "Porn" (207969) & "Sexy" (37914).
 
9
  sys.path.append('/home/ryn_mote/Misc/generative_recommender/gradio_video/automl/efficientnetv2/')
10
  import tensorflow as tf
11
  from tensorflow.keras import mixed_precision
 
12
 
13
+ physical_devices = tf.config.list_physical_devices('GPU')
14
+ if len(physical_devices) > 0:
15
+ tf.config.experimental.set_memory_growth(
16
+ physical_devices[0], True
17
+ )
18
 
19
  model = tf.keras.models.load_model('nsfweffnetv2-b02-3epochs.h5',custom_objects={"KerasLayer":hub.KerasLayer})
20
  # "The image classifier had been trained on 682550 images from the 5 classes "Drawing" (39026), "Hentai" (28134), "Neutral" (369507), "Porn" (207969) & "Sexy" (37914).