Spaces:
Running
Running
GitHub Actions commited on
Commit ·
a2e330e
1
Parent(s): 0474f3a
Sync from GitHub Actions
Browse files
app.py
CHANGED
|
@@ -6,13 +6,7 @@ from PIL import Image
|
|
| 6 |
ROOT_DIR = Path(__file__).resolve().parent
|
| 7 |
if str(ROOT_DIR) not in sys.path:
|
| 8 |
sys.path.insert(0, str(ROOT_DIR))
|
| 9 |
-
|
| 10 |
-
from src.inference import (
|
| 11 |
-
load_predictor,
|
| 12 |
-
render_metrics,
|
| 13 |
-
render_prediction_card,
|
| 14 |
-
render_top_predictions,
|
| 15 |
-
)
|
| 16 |
from autocatalog.utils.config import load_config
|
| 17 |
|
| 18 |
def main():
|
|
@@ -21,7 +15,7 @@ def main():
|
|
| 21 |
page_icon="🛍️",
|
| 22 |
layout="wide",
|
| 23 |
)
|
| 24 |
-
|
| 25 |
st.markdown(
|
| 26 |
"""
|
| 27 |
<style>
|
|
@@ -99,17 +93,13 @@ def main():
|
|
| 99 |
unsafe_allow_html=True,
|
| 100 |
)
|
| 101 |
|
| 102 |
-
config = load_config(
|
| 103 |
-
ROOT_DIR / "configs" / "config.yaml"
|
| 104 |
-
)
|
| 105 |
-
|
| 106 |
repo_id = config.get("model", {}).get(
|
| 107 |
"repo_id",
|
| 108 |
"mohsin416/autocatalogai-clip-multitask-v2",
|
| 109 |
)
|
| 110 |
|
| 111 |
inference_config = config.get("inference", {})
|
| 112 |
-
|
| 113 |
top_k = int(inference_config.get("top_k", 3))
|
| 114 |
device = inference_config.get("device")
|
| 115 |
default_consistency = bool(
|
|
@@ -123,7 +113,6 @@ def main():
|
|
| 123 |
'<div class="main-title">AutoCatalogAI V2</div>',
|
| 124 |
unsafe_allow_html=True,
|
| 125 |
)
|
| 126 |
-
|
| 127 |
st.markdown(
|
| 128 |
"""
|
| 129 |
<div class="subtitle">
|
|
@@ -172,7 +161,6 @@ def main():
|
|
| 172 |
|
| 173 |
with left_col:
|
| 174 |
st.subheader("Upload Product Image")
|
| 175 |
-
|
| 176 |
uploaded_file = st.file_uploader(
|
| 177 |
"Choose a product image",
|
| 178 |
type=["jpg", "jpeg", "png", "webp"],
|
|
@@ -181,7 +169,6 @@ def main():
|
|
| 181 |
|
| 182 |
if uploaded_file is not None:
|
| 183 |
image = Image.open(uploaded_file).convert("RGB")
|
| 184 |
-
|
| 185 |
st.image(
|
| 186 |
image,
|
| 187 |
caption="Uploaded Image",
|
|
@@ -190,7 +177,6 @@ def main():
|
|
| 190 |
|
| 191 |
with right_col:
|
| 192 |
st.subheader("Prediction Result")
|
| 193 |
-
|
| 194 |
if image is None:
|
| 195 |
st.info(
|
| 196 |
"Upload a fashion product image "
|
|
@@ -203,9 +189,7 @@ def main():
|
|
| 203 |
type="primary",
|
| 204 |
width="stretch",
|
| 205 |
):
|
| 206 |
-
with st.spinner(
|
| 207 |
-
"Predicting product attributes..."
|
| 208 |
-
):
|
| 209 |
result = predictor.predict(
|
| 210 |
image=image,
|
| 211 |
top_k=selected_top_k,
|
|
@@ -215,7 +199,6 @@ def main():
|
|
| 215 |
prediction = result["prediction"]
|
| 216 |
catalog_output = result["catalog_output"]
|
| 217 |
runtime = result["runtime"]
|
| 218 |
-
|
| 219 |
st.markdown(
|
| 220 |
f"""
|
| 221 |
<div class="catalog-box">
|
|
@@ -234,13 +217,8 @@ def main():
|
|
| 234 |
)
|
| 235 |
|
| 236 |
st.markdown("**Predicted Attributes**")
|
| 237 |
-
|
| 238 |
for task, task_result in prediction.items():
|
| 239 |
-
render_prediction_card(
|
| 240 |
-
task,
|
| 241 |
-
task_result,
|
| 242 |
-
)
|
| 243 |
-
|
| 244 |
if task_result.get("corrected"):
|
| 245 |
st.caption(
|
| 246 |
f"Corrected from: "
|
|
@@ -249,14 +227,8 @@ def main():
|
|
| 249 |
|
| 250 |
render_top_predictions(prediction)
|
| 251 |
st.markdown("**Runtime**")
|
| 252 |
-
st.write(
|
| 253 |
-
|
| 254 |
-
)
|
| 255 |
-
st.write(
|
| 256 |
-
f"Inference time: "
|
| 257 |
-
f"`{runtime['inference_time_ms']:.2f} ms`"
|
| 258 |
-
)
|
| 259 |
-
|
| 260 |
json_output = json.dumps(
|
| 261 |
catalog_output["json_export"],
|
| 262 |
indent=2,
|
|
@@ -272,10 +244,7 @@ def main():
|
|
| 272 |
)
|
| 273 |
|
| 274 |
with st.expander("Raw JSON Output"):
|
| 275 |
-
st.json(
|
| 276 |
-
catalog_output["json_export"]
|
| 277 |
-
)
|
| 278 |
-
|
| 279 |
|
| 280 |
if __name__ == "__main__":
|
| 281 |
main()
|
|
|
|
| 6 |
ROOT_DIR = Path(__file__).resolve().parent
|
| 7 |
if str(ROOT_DIR) not in sys.path:
|
| 8 |
sys.path.insert(0, str(ROOT_DIR))
|
| 9 |
+
from src.inference import load_predictor,render_metrics,render_prediction_card,render_top_predictions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
from autocatalog.utils.config import load_config
|
| 11 |
|
| 12 |
def main():
|
|
|
|
| 15 |
page_icon="🛍️",
|
| 16 |
layout="wide",
|
| 17 |
)
|
| 18 |
+
|
| 19 |
st.markdown(
|
| 20 |
"""
|
| 21 |
<style>
|
|
|
|
| 93 |
unsafe_allow_html=True,
|
| 94 |
)
|
| 95 |
|
| 96 |
+
config = load_config(ROOT_DIR / "configs" / "config.yaml")
|
|
|
|
|
|
|
|
|
|
| 97 |
repo_id = config.get("model", {}).get(
|
| 98 |
"repo_id",
|
| 99 |
"mohsin416/autocatalogai-clip-multitask-v2",
|
| 100 |
)
|
| 101 |
|
| 102 |
inference_config = config.get("inference", {})
|
|
|
|
| 103 |
top_k = int(inference_config.get("top_k", 3))
|
| 104 |
device = inference_config.get("device")
|
| 105 |
default_consistency = bool(
|
|
|
|
| 113 |
'<div class="main-title">AutoCatalogAI V2</div>',
|
| 114 |
unsafe_allow_html=True,
|
| 115 |
)
|
|
|
|
| 116 |
st.markdown(
|
| 117 |
"""
|
| 118 |
<div class="subtitle">
|
|
|
|
| 161 |
|
| 162 |
with left_col:
|
| 163 |
st.subheader("Upload Product Image")
|
|
|
|
| 164 |
uploaded_file = st.file_uploader(
|
| 165 |
"Choose a product image",
|
| 166 |
type=["jpg", "jpeg", "png", "webp"],
|
|
|
|
| 169 |
|
| 170 |
if uploaded_file is not None:
|
| 171 |
image = Image.open(uploaded_file).convert("RGB")
|
|
|
|
| 172 |
st.image(
|
| 173 |
image,
|
| 174 |
caption="Uploaded Image",
|
|
|
|
| 177 |
|
| 178 |
with right_col:
|
| 179 |
st.subheader("Prediction Result")
|
|
|
|
| 180 |
if image is None:
|
| 181 |
st.info(
|
| 182 |
"Upload a fashion product image "
|
|
|
|
| 189 |
type="primary",
|
| 190 |
width="stretch",
|
| 191 |
):
|
| 192 |
+
with st.spinner("Predicting product attributes..."):
|
|
|
|
|
|
|
| 193 |
result = predictor.predict(
|
| 194 |
image=image,
|
| 195 |
top_k=selected_top_k,
|
|
|
|
| 199 |
prediction = result["prediction"]
|
| 200 |
catalog_output = result["catalog_output"]
|
| 201 |
runtime = result["runtime"]
|
|
|
|
| 202 |
st.markdown(
|
| 203 |
f"""
|
| 204 |
<div class="catalog-box">
|
|
|
|
| 217 |
)
|
| 218 |
|
| 219 |
st.markdown("**Predicted Attributes**")
|
|
|
|
| 220 |
for task, task_result in prediction.items():
|
| 221 |
+
render_prediction_card(task,task_result,)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
if task_result.get("corrected"):
|
| 223 |
st.caption(
|
| 224 |
f"Corrected from: "
|
|
|
|
| 227 |
|
| 228 |
render_top_predictions(prediction)
|
| 229 |
st.markdown("**Runtime**")
|
| 230 |
+
st.write(f"Device: `{runtime['device']}`")
|
| 231 |
+
st.write(f"Inference time: "f"`{runtime['inference_time_ms']:.2f} ms`")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
json_output = json.dumps(
|
| 233 |
catalog_output["json_export"],
|
| 234 |
indent=2,
|
|
|
|
| 244 |
)
|
| 245 |
|
| 246 |
with st.expander("Raw JSON Output"):
|
| 247 |
+
st.json(catalog_output["json_export"])
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
if __name__ == "__main__":
|
| 250 |
main()
|