Spaces:
Sleeping
Sleeping
Raphaël Bournhonesque commited on
Commit ·
4123d5a
1
Parent(s): a332564
update demo
Browse files3 unmodified lines456789103 unmodified linescolorFrom: purplecolorTo: redsdk: streamlitsdk_version: 1.17.0app_file: app.pypinned: false---3 unmodified lines456789103 unmodified linescolorFrom: purplecolorTo: redsdk: streamlitsdk_version: 1.25.0app_file: app.pypinned: false---
12345678910111213141516171819202122232425262728293031323334354 unmodified lines4041424344454647483 unmodified lines525354555657585960616263646566676869707172737 unmodified lines8182838485868788899091929394959697import copyimport enumimport pandas as pdfrom typing import List, Optionalimport requestsimport streamlit as stMODEL_DESCRIPTION = """**keras_2_0**: Current production model\n**keras_image_embeddings_3_0**: same as `keras_300_epochs_3_0` but with image embedding as input\n**keras_300_epochs_3_0**: trained on 300 epochs with product name, ingredients, OCR-extracted ingredients and nutriments as input\n**keras_ingredient_ocr_3_0**: same as `keras_sota_3_0`, but trained on less epochs\n**keras_baseline_3_0**: model trained with product name, ingredients and nutriments as input\n**keras_original_3_0**: same inputs as **keras_2_0** (product name + ingredients), but retrained\n**keras_product_name_only_3_0**: model with only product name as input"""http_session = requests.Session()@enum.uniqueclass NeuralCategoryClassifierModel(enum.Enum):keras_2_0 = "keras-2.0"keras_image_embeddings_3_0 = "keras-image-embeddings-3-0"keras_300_epochs_3_0 = "keras-300-epochs-3-0"keras_ingredient_ocr_3_0 = "keras-ingredient-ocr-3.0"keras_baseline_3_0 = "keras-baseline-3.0"keras_original_3_0 = "keras-original-3.0"keras_product_name_only_3_0 = "keras-product-name-only-3.0"LOCAL_DB = Falseif LOCAL_DB:4 unmodified linesPREDICTION_URL = ROBOTOFF_BASE_URL + "/predict/category"@st.cachedef get_predictions(barcode: str, model_name: str, threshold: Optional[float] = None):data = {"barcode": barcode, "predictors": ["neural"], "neural_model_name": model_name}if threshold is not None:data["threshold"] = threshold3 unmodified linesdef display_predictions(barcode: str,model_names: List[str],threshold: Optional[float] = None,):debug = Nonefor model_name in model_names:response = get_predictions(barcode, model_name, threshold)response = copy.deepcopy(response)if model_name != NeuralCategoryClassifierModel.keras_2_0.name and "debug" in response:if debug is None:debug = response["debug"]response.pop("debug")st.markdown(f"**{model_name}**")st.write(pd.DataFrame(response["predictions"]))if debug is not None:st.markdown("**v3 debug information**")st.write(debug)7 unmodified lines)threshold = st.sidebar.number_input("Threshold", format="%f", value=0.5) or Nonest.sidebar.write("---\n# Model description\n" + MODEL_DESCRIPTION)model_names = st.multiselect("Name of the model",[x.name for x in NeuralCategoryClassifierModel],default=[x.name for x in NeuralCategoryClassifierModel],)if barcode:barcode = barcode.strip()display_predictions(barcode=barcode,threshold=threshold,model_names=model_names,)123456789101112134 unmodified lines1819202122232425263 unmodified lines303132333435363738394041424344454647487 unmodified lines565758596061626364import copyimport pandas as pdfrom typing import Optionalimport requestsimport streamlit as sthttp_session = requests.Session()LOCAL_DB = Falseif LOCAL_DB:4 unmodified linesPREDICTION_URL = ROBOTOFF_BASE_URL + "/predict/category"@st.cache_datadef get_predictions(barcode: str, threshold: Optional[float] = None):data = {"barcode": barcode, "predictors": ["neural"]}if threshold is not None:data["threshold"] = threshold3 unmodified linesdef display_predictions(barcode: str,threshold: Optional[float] = None,):debug = Noneresponse = get_predictions(barcode, threshold)response = copy.deepcopy(response)if "debug" in response:if debug is None:debug = response["debug"]response.pop("debug")st.write(pd.DataFrame(response["predictions"]))if debug is not None:st.markdown("**Debug information**")st.write(debug)7 unmodified lines)threshold = st.sidebar.number_input("Threshold", format="%f", value=0.5) or Noneif barcode:barcode = barcode.strip()display_predictions(barcode=barcode,threshold=threshold,)
README.md+1-1
app.py+12-45