D0k-tor commited on
Commit
e667bf2
·
1 Parent(s): 0ab9ff9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -17
app.py CHANGED
@@ -1,31 +1,14 @@
1
  import torch
2
  import re
3
  import gradio as gr
4
- # import streamlit as st
5
  from PIL import Image
6
 
7
- # st.title("Image Caption Generator")
8
  from transformers import AutoTokenizer, ViTFeatureExtractor, VisionEncoderDecoderModel
9
  import os
10
  import tensorflow as tf
11
  os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
12
 
13
  device='cpu'
14
- # encoder_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
15
- # decoder_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
16
- # model_checkpoint = "nlpconnect/vit-gpt2-image-captioning"
17
-
18
- # feature_extractor = ViTFeatureExtractor.from_pretrained(encoder_checkpoint)
19
- # tokenizer = AutoTokenizer.from_pretrained(decoder_checkpoint)
20
- # model = VisionEncoderDecoderModel.from_pretrained(model_checkpoint).to(device)
21
-
22
- # def predict(image, max_length=64, num_beams=4):
23
- # image = image.convert('RGB')
24
- # image = feature_extractor(image, return_tensors="pt").pixel_values.to(device)
25
- # clean_text = lambda x: x.replace('<|endoftext|>','').split('\n')[0]
26
- # caption_ids = model.generate(image, max_length = max_length)[0]
27
- # caption_text = clean_text(tokenizer.decode(caption_ids))
28
- # return caption_text
29
 
30
  model_id = "nttdataspain/vit-gpt2-coco-lora"
31
  model = VisionEncoderDecoderModel.from_pretrained(model_id)
 
1
  import torch
2
  import re
3
  import gradio as gr
 
4
  from PIL import Image
5
 
 
6
  from transformers import AutoTokenizer, ViTFeatureExtractor, VisionEncoderDecoderModel
7
  import os
8
  import tensorflow as tf
9
  os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
10
 
11
  device='cpu'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  model_id = "nttdataspain/vit-gpt2-coco-lora"
14
  model = VisionEncoderDecoderModel.from_pretrained(model_id)