Add title and examples

#2
by hysts HF staff - opened
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ *.jpg filter=lfs diff=lfs merge=lfs -text
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import gradio as gr
2
  import open_clip
3
  import torch
@@ -8,14 +10,23 @@ model, _, transform = open_clip.create_model_and_transforms(
8
  "coca_ViT-L-14",
9
  pretrained="mscoco_finetuned_laion2B-s13B-b90k"
10
  )
11
-
12
  model.to(device)
13
 
 
14
  def output_generate(image):
15
  im = transform(image).unsqueeze(0).to(device)
16
  with torch.no_grad(), torch.cuda.amp.autocast():
17
  generated = model.generate(im, seq_len=20)
18
  return open_clip.decode(generated[0].detach()).split("<end_of_text>")[0].replace("<start_of_text>", "")
19
 
20
- iface = gr.Interface(fn=output_generate, inputs=gr.Image(type="pil"), outputs="text")
21
- iface.launch()
 
 
 
 
 
 
 
 
 
 
1
+ import pathlib
2
+
3
  import gradio as gr
4
  import open_clip
5
  import torch
 
10
  "coca_ViT-L-14",
11
  pretrained="mscoco_finetuned_laion2B-s13B-b90k"
12
  )
 
13
  model.to(device)
14
 
15
+
16
  def output_generate(image):
17
  im = transform(image).unsqueeze(0).to(device)
18
  with torch.no_grad(), torch.cuda.amp.autocast():
19
  generated = model.generate(im, seq_len=20)
20
  return open_clip.decode(generated[0].detach()).split("<end_of_text>")[0].replace("<start_of_text>", "")
21
 
22
+
23
+ paths = sorted(pathlib.Path("images").glob("*.jpg"))
24
+
25
+ iface = gr.Interface(
26
+ fn=output_generate,
27
+ inputs=gr.Image(label="Input image", type="pil"),
28
+ outputs=gr.Text(label="Caption output"),
29
+ title="CoCa: Contrastive Captioners are Image-Text Foundation Models",
30
+ examples=[path.as_posix() for path in paths],
31
+ )
32
+ iface.launch()
images/pexels-andrea-piacquadio-3756616.jpg ADDED

Git LFS Details

  • SHA256: 6574dc0bebddd60d48aa5aba76b453c06bdf3217d2d8336faa85bcba3231715e
  • Pointer size: 131 Bytes
  • Size of remote file: 104 kB
images/pexels-george-milton-7034219.jpg ADDED

Git LFS Details

  • SHA256: 3524008fb1bdd74af43028ffa0dc33cdde369bb6955bfc22fb60399df2803f47
  • Pointer size: 130 Bytes
  • Size of remote file: 76 kB
images/pexels-katarzyna-modrzejewska-1314550.jpg ADDED

Git LFS Details

  • SHA256: 9b7cee213a4e35f6ee238c21743495fb941896768a07883ca793d96689746942
  • Pointer size: 130 Bytes
  • Size of remote file: 67.9 kB