unography commited on
Commit
4d677d2
1 Parent(s): 1e253bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -6,22 +6,22 @@ import gradio as gr
6
  import PIL.Image
7
  import spaces
8
  import torch
9
- from transformers import AutoModelForCausalLM, AutoProcessor
10
 
11
- DESCRIPTION = "# Image Captioning with GIT"
12
 
13
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
14
 
15
- model_id = "microsoft/git-large-coco"
16
- processor = AutoProcessor.from_pretrained(model_id)
17
- model = AutoModelForCausalLM.from_pretrained(model_id).to(device)
18
 
19
 
20
  @spaces.GPU
21
  def run(image: PIL.Image.Image) -> str:
22
  inputs = processor(images=image, return_tensors="pt").to(device)
23
- generated_ids = model.generate(pixel_values=inputs.pixel_values, num_beams=3, max_length=20, min_length=5)
24
- generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
25
  return generated_caption
26
 
27
 
 
6
  import PIL.Image
7
  import spaces
8
  import torch
9
+ from transformers import BlipProcessor, BlipForConditionalGeneration
10
 
11
+ DESCRIPTION = "# Image Captioning with LongCap"
12
 
13
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
14
 
15
+ model_id = "unography/blip-long-cap"
16
+ processor = BlipProcessor.from_pretrained(model_id)
17
+ model = BlipForConditionalGeneration.from_pretrained(model_id).to(device)
18
 
19
 
20
  @spaces.GPU
21
  def run(image: PIL.Image.Image) -> str:
22
  inputs = processor(images=image, return_tensors="pt").to(device)
23
+ out = model.generate(pixel_values=pixel_values, max_length=300)
24
+ generated_caption = processor.decode(out[0], skip_special_tokens=True)
25
  return generated_caption
26
 
27