Spaces:
Sleeping
Sleeping
| from fastai.vision.all import * | |
| import gradio as gr | |
| # 1. Load the model | |
| learn = load_learner('hydration_model.pkl') | |
| # 2. Get the labels from the model automatically | |
| categories = learn.dls.vocab | |
| # 3. Define the function | |
| def classify_image(img): | |
| pred, idx, probs = learn.predict(img) | |
| return dict(zip(categories, map(float, probs))) | |
| # 4. Build the interface | |
| image = gr.Image(type="pil") # Allow uploading or taking a photo | |
| label = gr.Label() | |
| examples = [] # You can add example filenames here later if you upload images | |
| intf = gr.Interface(fn=classify_image, inputs=image, outputs=label) | |
| intf.launch(inline=False) |