Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,14 +1,19 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
import torch
|
5 |
|
6 |
import streamlit as st
|
7 |
from PIL import Image
|
8 |
-
from transformers import GPT2TokenizerFast, ViTImageProcessor, VisionEncoderDecoderModel,RobertaTokenizerFast, VisionEncoderDecoderModel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
|
11 |
-
#from transformers import BlipProcessor, BlipForConditionalGeneration
|
12 |
|
13 |
def set_page_config():
|
14 |
st.set_page_config(
|
@@ -20,9 +25,9 @@ def set_page_config():
|
|
20 |
def initialize_model():
|
21 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
22 |
# load a fine-tuned image captioning model and corresponding tokenizer and image processor
|
23 |
-
model =
|
24 |
-
tokenizer =
|
25 |
-
image_processor = ViTImageProcessor.from_pretrained("
|
26 |
return image_processor, model,tokenizer, device
|
27 |
|
28 |
def upload_image():
|
|
|
1 |
+
# !pip install torch
|
2 |
+
# import torch
|
|
|
|
|
3 |
|
4 |
import streamlit as st
|
5 |
from PIL import Image
|
6 |
+
# from transformers import GPT2TokenizerFast, ViTImageProcessor, VisionEncoderDecoderModel,RobertaTokenizerFast, VisionEncoderDecoderModel
|
7 |
+
#from transformers import BlipProcessor, BlipForConditionalGeneration
|
8 |
+
|
9 |
+
|
10 |
+
# Load model directly
|
11 |
+
from transformers import AutoTokenizer, AutoModel
|
12 |
+
|
13 |
+
# tokenizer = AutoTokenizer.from_pretrained("sourabhbargi11/Caption_generator_model")
|
14 |
+
# model = AutoModel.from_pretrained("sourabhbargi11/Caption_generator_model")
|
15 |
|
16 |
|
|
|
17 |
|
18 |
def set_page_config():
|
19 |
st.set_page_config(
|
|
|
25 |
def initialize_model():
|
26 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
27 |
# load a fine-tuned image captioning model and corresponding tokenizer and image processor
|
28 |
+
model = AutoModel.from_pretrained("sourabhbargi11/Caption_generator_model").to(device)
|
29 |
+
tokenizer = AutoTokenizer.from_pretrained("sourabhbargi11/Caption_generator_model")
|
30 |
+
image_processor = ViTImageProcessor.from_pretrained("sourabhbargi11/Caption_generator_model")
|
31 |
return image_processor, model,tokenizer, device
|
32 |
|
33 |
def upload_image():
|