Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,16 @@
|
|
1 |
# !pip install torch
|
2 |
# import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
import streamlit as st
|
5 |
from PIL import Image
|
@@ -24,10 +35,10 @@ def set_page_config():
|
|
24 |
|
25 |
def initialize_model():
|
26 |
device = 'cpu'
|
27 |
-
|
28 |
-
model =
|
29 |
-
tokenizer =
|
30 |
-
image_processor = ViTImageProcessor.from_pretrained("
|
31 |
return image_processor, model,tokenizer, device
|
32 |
|
33 |
def upload_image():
|
|
|
1 |
# !pip install torch
|
2 |
# import torch
|
3 |
+
from transformers import AutoTokenizer, AutoModel ,AutoConfig
|
4 |
+
import torch
|
5 |
+
from transformers import ViTImageProcessor, VisionEncoderDecoderModel,RobertaTokenizerFast
|
6 |
+
import PIL
|
7 |
+
|
8 |
+
|
9 |
+
# Move model to GPU , depnding on device
|
10 |
+
device2 = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
11 |
+
# Load the model
|
12 |
+
|
13 |
+
|
14 |
|
15 |
import streamlit as st
|
16 |
from PIL import Image
|
|
|
35 |
|
36 |
def initialize_model():
|
37 |
device = 'cpu'
|
38 |
+
config = AutoConfig.from_pretrained("sourabhbargi11/Caption_generator_model")
|
39 |
+
model = VisionEncoderDecoderModel.from_pretrained("sourabhbargi11/Caption_generator_model", config=config).to(device)
|
40 |
+
tokenizer = RobertaTokenizerFast.from_pretrained("roberta-base")
|
41 |
+
image_processor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224",device=device)
|
42 |
return image_processor, model,tokenizer, device
|
43 |
|
44 |
def upload_image():
|