Spaces:
Runtime error
Runtime error
Fixing issue
Browse files
app.py
CHANGED
@@ -57,16 +57,17 @@ st.caption("For more detail: [Github link](https://github.com/SmithaUpadhyaya/fa
|
|
57 |
|
58 |
#Select few sample images for the catagory of cloths
|
59 |
st.caption("Select image:")
|
|
|
60 |
option = st.selectbox('From sample', ('None', 'dress', 'earrings', 'sweater', 'sunglasses', 'shoe', 'hat', 'heels', 'socks', 'tee', 'bracelet'), index = 0)
|
61 |
st.text("Or")
|
62 |
file_name = st.file_uploader(label = "Upload an image", accept_multiple_files = False)
|
63 |
|
|
|
64 |
btn_click = st.button('Generate')
|
65 |
st.caption("Application deployed on CPU basic with 16GB RAM")
|
66 |
|
67 |
if btn_click:
|
68 |
|
69 |
-
image = None
|
70 |
if file_name is not None:
|
71 |
|
72 |
image = Image.open(file_name)
|
@@ -78,6 +79,11 @@ if btn_click:
|
|
78 |
|
79 |
if image is not None:
|
80 |
|
|
|
|
|
|
|
|
|
|
|
81 |
if 'init_model_required' not in st.session_state:
|
82 |
with st.spinner('Initializing model...'):
|
83 |
|
@@ -93,11 +99,7 @@ if btn_click:
|
|
93 |
processor = st.session_state.processor
|
94 |
model = st.session_state.model
|
95 |
|
96 |
-
with st.spinner('Generating Caption...'):
|
97 |
-
|
98 |
-
image_col, caption_text = st.columns(2)
|
99 |
-
image_col.header("Image")
|
100 |
-
image_col.image(image.resize((252,252)), use_column_width = True)
|
101 |
|
102 |
#Preprocess the image
|
103 |
#Inferance on GPU. When used this on GPU will get errors like: "slow_conv2d_cpu" not implemented for 'Half'" , " Input type (float) and bias type (struct c10::Half)"
|
@@ -110,10 +112,9 @@ if btn_click:
|
|
110 |
|
111 |
#Predict the caption for the imahe
|
112 |
generated_ids = model.generate(pixel_values = pixel_values, max_length = 25)
|
113 |
-
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
114 |
|
115 |
-
#Output the predict text
|
116 |
-
caption_text.header("Generated Caption")
|
117 |
caption_text.text(generated_caption)
|
118 |
|
119 |
|
|
|
57 |
|
58 |
#Select few sample images for the catagory of cloths
|
59 |
st.caption("Select image:")
|
60 |
+
option = 'None'
|
61 |
option = st.selectbox('From sample', ('None', 'dress', 'earrings', 'sweater', 'sunglasses', 'shoe', 'hat', 'heels', 'socks', 'tee', 'bracelet'), index = 0)
|
62 |
st.text("Or")
|
63 |
file_name = st.file_uploader(label = "Upload an image", accept_multiple_files = False)
|
64 |
|
65 |
+
image = None
|
66 |
btn_click = st.button('Generate')
|
67 |
st.caption("Application deployed on CPU basic with 16GB RAM")
|
68 |
|
69 |
if btn_click:
|
70 |
|
|
|
71 |
if file_name is not None:
|
72 |
|
73 |
image = Image.open(file_name)
|
|
|
79 |
|
80 |
if image is not None:
|
81 |
|
82 |
+
image_col, caption_text = st.columns(2)
|
83 |
+
image_col.header("Image")
|
84 |
+
caption_text.header("Generated Caption")
|
85 |
+
image_col.image(image.resize((252,252)), use_column_width = True)
|
86 |
+
|
87 |
if 'init_model_required' not in st.session_state:
|
88 |
with st.spinner('Initializing model...'):
|
89 |
|
|
|
99 |
processor = st.session_state.processor
|
100 |
model = st.session_state.model
|
101 |
|
102 |
+
with st.spinner('Generating Caption...'):
|
|
|
|
|
|
|
|
|
103 |
|
104 |
#Preprocess the image
|
105 |
#Inferance on GPU. When used this on GPU will get errors like: "slow_conv2d_cpu" not implemented for 'Half'" , " Input type (float) and bias type (struct c10::Half)"
|
|
|
112 |
|
113 |
#Predict the caption for the imahe
|
114 |
generated_ids = model.generate(pixel_values = pixel_values, max_length = 25)
|
115 |
+
generated_caption = processor.batch_decode(generated_ids, skip_special_tokens = True)[0]
|
116 |
|
117 |
+
#Output the predict text
|
|
|
118 |
caption_text.text(generated_caption)
|
119 |
|
120 |
|