Nepjune commited on
Commit
7bf188c
·
verified ·
1 Parent(s): 651ec42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -1,14 +1,20 @@
1
- from transformers import ViTFeatureExtractor, ViTForImageCaptioning, AutoTokenizer
 
 
 
 
2
  import torch
3
- from PIL import Image
4
 
5
- model = ViTForImageCaptioning.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
6
- feature_extractor = ViTFeatureExtractor.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
7
- tokenizer = AutoTokenizer.from_pretrained("nlpconnect/vit-gpt2-image-captioning")
8
 
9
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10
  model.to(device)
11
 
 
 
 
 
12
  max_length = 16
13
  num_beams = 4
14
  gen_kwargs = {"max_length": max_length, "num_beams": num_beams}
 
1
+ from __future__ import annotations
2
+
3
+ import gradio as gr
4
+ import PIL.Image
5
+ import spaces
6
  import torch
7
+ from transformers import AutoProcessor, BlipForConditionalGeneration
8
 
9
+ DESCRIPTION = "# Image Captioning with BLIP"
 
 
10
 
11
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
12
  model.to(device)
13
 
14
+ model_id = "Salesforce/blip-image-captioning-large"
15
+ processor = AutoProcessor.from_pretrained(model_id)
16
+ model = BlipForConditionalGeneration.from_pretrained(model_id).to(device)
17
+
18
  max_length = 16
19
  num_beams = 4
20
  gen_kwargs = {"max_length": max_length, "num_beams": num_beams}