tombio commited on
Commit
ba37a67
1 Parent(s): be16b69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -16,6 +16,9 @@ import clip
16
 
17
  from PIL import Image
18
 
 
 
 
19
  from huggingface_hub import hf_hub_download
20
  ckpt = hf_hub_download(repo_id="lambdalabs/image-mixer", filename="image-mixer-pruned.ckpt", cache_dir="/data/.cache")
21
  config = hf_hub_download(repo_id="lambdalabs/image-mixer", filename="image-mixer-config.yaml", cache_dir="/data/.cache")
@@ -25,6 +28,8 @@ model = load_model_from_config(config, ckpt, device=device, verbose=False)
25
  model = model.to(device).half()
26
 
27
  clip_model, preprocess = clip.load("ViT-L/14", device=device)
 
 
28
 
29
  n_inputs = 5
30
 
@@ -115,10 +120,16 @@ def run_image_mixer(args):
115
  torch.cuda.empty_cache()
116
  return ims[0]
117
 
 
 
 
 
118
 
119
  import gradio
120
 
121
  def boutsify(person):
 
 
122
  inputs = [
123
  "Image", "Image", "Text/URL", "Image", "Nothing",
124
  "","","flowers","","",
@@ -131,10 +142,10 @@ def boutsify(person):
131
  3.0, 1, 0, 40,
132
  ]
133
 
134
- return run(inputs)
135
 
136
  gradio_interface = gradio.Interface(
137
- fn=my_inference_function,
138
  inputs="image",
139
  outputs="image",
140
  title="Boutsify images",
 
16
 
17
  from PIL import Image
18
 
19
+ from fastai.vision.all import *
20
+ import skimage
21
+
22
  from huggingface_hub import hf_hub_download
23
  ckpt = hf_hub_download(repo_id="lambdalabs/image-mixer", filename="image-mixer-pruned.ckpt", cache_dir="/data/.cache")
24
  config = hf_hub_download(repo_id="lambdalabs/image-mixer", filename="image-mixer-config.yaml", cache_dir="/data/.cache")
 
28
  model = model.to(device).half()
29
 
30
  clip_model, preprocess = clip.load("ViT-L/14", device=device)
31
+ gender_learn = load_learner('model.pkl')
32
+ gender_labels = gender_learn.dls.vocab
33
 
34
  n_inputs = 5
35
 
 
120
  torch.cuda.empty_cache()
121
  return ims[0]
122
 
123
+ def guess_gender(img):
124
+ pred,pred_idx,probs = gender_learn.predict(img)
125
+ return {gender_labels[i]: float(probs[i]) for i in range(len(gender_labels))}
126
+
127
 
128
  import gradio
129
 
130
  def boutsify(person):
131
+ print(guess_gender(person))
132
+
133
  inputs = [
134
  "Image", "Image", "Text/URL", "Image", "Nothing",
135
  "","","flowers","","",
 
142
  3.0, 1, 0, 40,
143
  ]
144
 
145
+ return run_image_mixer(inputs)
146
 
147
  gradio_interface = gradio.Interface(
148
+ fn=boutsify,
149
  inputs="image",
150
  outputs="image",
151
  title="Boutsify images",