awacke1 commited on
Commit
6042ee3
·
1 Parent(s): 2b45428

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -8
app.py CHANGED
@@ -5,12 +5,8 @@ from transformers import VisionEncoderDecoderModel, ViTFeatureExtractor, AutoTok
5
  model = VisionEncoderDecoderModel.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
-
13
-
14
  max_length = 16
15
  num_beams = 4
16
  gen_kwargs = {"max_length": max_length, "num_beams": num_beams}
@@ -43,21 +39,21 @@ def predict(image,max_length=64, num_beams=4):
43
 
44
  description= "NLP Image Understanding"
45
  title = "NLP Image Understanding"
46
- article = "nlpconnect/vit-gpt2-image-captioning"
47
 
48
  input = gr.inputs.Image(label="Upload your Image", type = 'pil', optional=True)
49
  output = gr.outputs.Textbox(type="auto",label="Captions")
 
50
  #examples = [['35-Favorite-Games.jpg']]
51
- examples = [f"{i}.jpg" for i in range(1,7)]
52
 
53
  interface = gr.Interface(
54
  fn=predict,
55
  inputs = input,
56
- theme="grass",
57
  outputs=output,
58
  examples = examples,
59
  title=title,
60
  description=description,
61
  article = article,
62
  )
63
- interface.launch(debug=True)
 
5
  model = VisionEncoderDecoderModel.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
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
9
  model.to(device)
 
 
 
10
  max_length = 16
11
  num_beams = 4
12
  gen_kwargs = {"max_length": max_length, "num_beams": num_beams}
 
39
 
40
  description= "NLP Image Understanding"
41
  title = "NLP Image Understanding"
42
+ article = "nlpconnect vit-gpt2-image-captioning"
43
 
44
  input = gr.inputs.Image(label="Upload your Image", type = 'pil', optional=True)
45
  output = gr.outputs.Textbox(type="auto",label="Captions")
46
+
47
  #examples = [['35-Favorite-Games.jpg']]
48
+ examples = [f"{i}.jpg" for i in range(1,10)]
49
 
50
  interface = gr.Interface(
51
  fn=predict,
52
  inputs = input,
 
53
  outputs=output,
54
  examples = examples,
55
  title=title,
56
  description=description,
57
  article = article,
58
  )
59
+ interface.launch()