zeddotes commited on
Commit
896413c
·
1 Parent(s): 75aecc2

updated app with my model

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -7,9 +7,12 @@ processor = BlipProcessor.from_pretrained("zeddotes/blip-computer-thoughts")
7
  model = BlipForConditionalGeneration.from_pretrained("zeddotes/blip-computer-thoughts")
8
 
9
  def caption_image(image):
 
 
10
  inputs = processor(images=image, return_tensors="pt")
11
  with torch.no_grad():
12
- generated_ids = model.generate(**inputs)
 
13
  caption = processor.decode(generated_ids[0], skip_special_tokens=True)
14
  return caption
15
 
@@ -17,8 +20,8 @@ demo = gr.Interface(
17
  fn=caption_image,
18
  inputs=gr.Image(type="pil"),
19
  outputs="text",
20
- title="My Fine-Tuned Model"
21
  )
22
 
23
  if __name__ == "__main__":
24
- demo.launch()
 
7
  model = BlipForConditionalGeneration.from_pretrained("zeddotes/blip-computer-thoughts")
8
 
9
  def caption_image(image):
10
+ # image is a PIL Image from Gradio
11
+ # Convert to model inputs
12
  inputs = processor(images=image, return_tensors="pt")
13
  with torch.no_grad():
14
+ # Generate text from the model
15
+ generated_ids = model.generate(**inputs, max_length=50)
16
  caption = processor.decode(generated_ids[0], skip_special_tokens=True)
17
  return caption
18
 
 
20
  fn=caption_image,
21
  inputs=gr.Image(type="pil"),
22
  outputs="text",
23
+ title="My Fine-Tuned BLIP Model"
24
  )
25
 
26
  if __name__ == "__main__":
27
+ demo.launch()