Upyaya commited on
Commit
13bfb69
1 Parent(s): f6f902a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -23,27 +23,27 @@ map_sampleid_name = {
23
  'tee': 'e2d8637a-5478-429d-a2a8-3d5859dbc64d.jpeg',
24
  'bracelet': 'e78518ac-0f54-4483-a233-fad6511f0b86.jpeg'
25
  }
26
- #init_model_required = True
27
 
28
- def init_model():
29
 
30
- #if init_model_required:
31
 
32
- #Preprocess input
33
- processor = Blip2Processor.from_pretrained(preprocess_ckp)
34
 
35
- #Model
36
- #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
37
- #model = Blip2ForConditionalGeneration.from_pretrained(base_model_ckp, load_in_8bit = True, device_map = "auto")
38
 
39
- #Inferance on CPU device
40
- model = Blip2ForConditionalGeneration.from_pretrained(base_model_ckp)
41
 
42
- model = PeftModel.from_pretrained(model, peft_model_ckp)
43
 
44
- #init_model_required = False
45
 
46
- return processor, model
47
 
48
  #def main():
49
 
@@ -63,6 +63,7 @@ st.text("Or")
63
  file_name = st.file_uploader(label = "Upload an image", accept_multiple_files = False)
64
 
65
  btn_click = st.button('Generate')
 
66
 
67
  if btn_click:
68
 
@@ -79,7 +80,7 @@ if btn_click:
79
  if image is not None:
80
 
81
  with st.spinner('Initializing model...'):
82
- processor, model = init_model()
83
 
84
  with st.spinner('Generating Caption...'):
85
 
@@ -104,7 +105,6 @@ if btn_click:
104
  caption_text.header("Generated Caption")
105
  caption_text.text(generated_caption)
106
 
107
- st.caption("Application deployed on CPU basic with 16GB RAM")
108
 
109
  #if __name__ == "__main__":
110
  # main()
 
23
  'tee': 'e2d8637a-5478-429d-a2a8-3d5859dbc64d.jpeg',
24
  'bracelet': 'e78518ac-0f54-4483-a233-fad6511f0b86.jpeg'
25
  }
26
+ init_model_required = True
27
 
28
+ def init_model(init_model_required):
29
 
30
+ if init_model_required:
31
 
32
+ #Preprocess input
33
+ processor = Blip2Processor.from_pretrained(preprocess_ckp)
34
 
35
+ #Model
36
+ #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
37
+ #model = Blip2ForConditionalGeneration.from_pretrained(base_model_ckp, load_in_8bit = True, device_map = "auto")
38
 
39
+ #Inferance on CPU device
40
+ model = Blip2ForConditionalGeneration.from_pretrained(base_model_ckp)
41
 
42
+ model = PeftModel.from_pretrained(model, peft_model_ckp)
43
 
44
+ init_model_required = False
45
 
46
+ return processor, model, init_model_required
47
 
48
  #def main():
49
 
 
63
  file_name = st.file_uploader(label = "Upload an image", accept_multiple_files = False)
64
 
65
  btn_click = st.button('Generate')
66
+ st.caption("Application deployed on CPU basic with 16GB RAM")
67
 
68
  if btn_click:
69
 
 
80
  if image is not None:
81
 
82
  with st.spinner('Initializing model...'):
83
+ processor, model, init_model_required = init_model(init_model_required)
84
 
85
  with st.spinner('Generating Caption...'):
86
 
 
105
  caption_text.header("Generated Caption")
106
  caption_text.text(generated_caption)
107
 
 
108
 
109
  #if __name__ == "__main__":
110
  # main()