awacke1 commited on
Commit
a0e9621
1 Parent(s): b6faabb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
  import os
3
  import gradio as gr
4
  import torch
@@ -13,11 +12,11 @@ DEFAULT_PROMPT = "<image>"
13
 
14
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
15
 
16
- model = FlamingoModel.from_pretrained('dhansmair/flamingo-tiny')
17
  model.to(device)
18
  model.eval()
19
 
20
- processor = FlamingoProcessor(model.config, load_vision_processor=True)
21
 
22
  # setup some example images
23
  examples = []
@@ -30,10 +29,11 @@ if os.path.isdir(EXAMPLES_DIR):
30
  def predict_caption(image, prompt):
31
  assert isinstance(prompt, str)
32
 
33
- features = processor.extract_features(image).to(device)
34
- caption = model.generate_captions(processor,
35
- visual_features=features,
36
- prompt=prompt)
 
37
 
38
  if isinstance(caption, list):
39
  caption = caption[0]
@@ -46,4 +46,4 @@ iface = gr.Interface(fn=predict_caption,
46
  examples=examples,
47
  outputs="text")
48
 
49
- iface.launch()
 
 
1
  import os
2
  import gradio as gr
3
  import torch
 
12
 
13
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
14
 
15
+ model = FlamingoModel.from_pretrained('dhansmair/flamingo-mini')
16
  model.to(device)
17
  model.eval()
18
 
19
+ processor = FlamingoProcessor(model.config, device=device)
20
 
21
  # setup some example images
22
  examples = []
 
29
  def predict_caption(image, prompt):
30
  assert isinstance(prompt, str)
31
 
32
+ caption = model.generate_captions(
33
+ processor,
34
+ images=image,
35
+ prompt=prompt
36
+ )
37
 
38
  if isinstance(caption, list):
39
  caption = caption[0]
 
46
  examples=examples,
47
  outputs="text")
48
 
49
+ iface.launch()