Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,43 +12,44 @@ peft_model_ckp = "./model/blip2_peft" #PEFT model checkpoint path
|
|
12 |
sample_img_path = "./sample_images/"
|
13 |
|
14 |
#init_model_required = True
|
15 |
-
#processor = None
|
16 |
-
#model = None
|
17 |
|
18 |
-
|
19 |
|
20 |
#if init_model_required:
|
21 |
|
22 |
-
#Preprocess input
|
23 |
-
processor = Blip2Processor.from_pretrained(preprocess_ckp)
|
24 |
|
25 |
-
#Model
|
26 |
-
#Inferance on GPU device. Will give error in CPU system, as "load_in_8bit" is an setting of bitsandbytes library and only works for GPU
|
27 |
-
#model = Blip2ForConditionalGeneration.from_pretrained(base_model_ckp, load_in_8bit = True, device_map = "auto")
|
28 |
|
29 |
-
#Inferance on CPU device
|
30 |
-
model = Blip2ForConditionalGeneration.from_pretrained(base_model_ckp)
|
31 |
|
32 |
-
model = PeftModel.from_pretrained(model, peft_model_ckp)
|
33 |
|
34 |
#init_model_required = False
|
35 |
|
|
|
36 |
|
37 |
|
38 |
def main():
|
39 |
|
40 |
st.title("Fashion Image Caption using BLIP2")
|
41 |
|
42 |
-
#init_model()
|
43 |
|
44 |
#Select few sample images for the catagory of cloths
|
45 |
-
|
46 |
-
|
47 |
file_name = st.file_uploader("Upload an image")
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
# file_name = os.path.join(sample_img_path, option)
|
52 |
|
53 |
if file_name is not None:
|
54 |
|
@@ -74,6 +75,7 @@ def main():
|
|
74 |
#Output the predict text
|
75 |
caption_text.header("Generated Caption")
|
76 |
caption_text.text(generated_caption)
|
|
|
77 |
|
78 |
if __name__ == "__main__":
|
79 |
main()
|
|
|
12 |
sample_img_path = "./sample_images/"
|
13 |
|
14 |
#init_model_required = True
|
|
|
|
|
15 |
|
16 |
+
def init_model():
|
17 |
|
18 |
#if init_model_required:
|
19 |
|
20 |
+
#Preprocess input
|
21 |
+
processor = Blip2Processor.from_pretrained(preprocess_ckp)
|
22 |
|
23 |
+
#Model
|
24 |
+
#Inferance on GPU device. Will give error in CPU system, as "load_in_8bit" is an setting of bitsandbytes library and only works for GPU
|
25 |
+
#model = Blip2ForConditionalGeneration.from_pretrained(base_model_ckp, load_in_8bit = True, device_map = "auto")
|
26 |
|
27 |
+
#Inferance on CPU device
|
28 |
+
model = Blip2ForConditionalGeneration.from_pretrained(base_model_ckp)
|
29 |
|
30 |
+
model = PeftModel.from_pretrained(model, peft_model_ckp)
|
31 |
|
32 |
#init_model_required = False
|
33 |
|
34 |
+
return processor, model
|
35 |
|
36 |
|
37 |
def main():
|
38 |
|
39 |
st.title("Fashion Image Caption using BLIP2")
|
40 |
|
41 |
+
#processor, model = init_model()
|
42 |
|
43 |
#Select few sample images for the catagory of cloths
|
44 |
+
option = st.selectbox('Select from sample an images', ('cap', 'tee', 'dress'), index = -1)
|
45 |
+
st.text("OR")
|
46 |
file_name = st.file_uploader("Upload an image")
|
47 |
+
st.text(option)
|
48 |
+
|
49 |
+
"""
|
50 |
+
if file_name is None and option is not None:
|
51 |
|
52 |
+
file_name = os.path.join(sample_img_path, option)
|
|
|
|
|
53 |
|
54 |
if file_name is not None:
|
55 |
|
|
|
75 |
#Output the predict text
|
76 |
caption_text.header("Generated Caption")
|
77 |
caption_text.text(generated_caption)
|
78 |
+
"""
|
79 |
|
80 |
if __name__ == "__main__":
|
81 |
main()
|