Download app.py from gowthM23/yourser: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/spaces/gowthM23/yourser/resolve/main/app.py
- Command line
-
hf download hf://spaces/gowthM23/yourser/app.py
-
curl -L -o app.py https://huggingface.co/spaces/gowthM23/yourser/resolve/main/app.py
1.22 kB
| import subprocess | |
| import sys | |
| def install(package): | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", package]) | |
| install('fastai') | |
| install('torch') | |
| import streamlit as st | |
| from fastai.vision.all import * | |
| from PIL import Image | |
| # Load the model (ensure model file is in the same directory or provide correct path) | |
| def load_model(): | |
| # Replace 'model.pkl' with your model file | |
| model = load_learner('model6.pkl') | |
| return model | |
| # Load the model | |
| model = load_model() | |
| # Streamlit application | |
| st.title("Image Classification with fastai") | |
| # Image upload | |
| uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) | |
| if uploaded_file: | |
| # Open and display the image | |
| image = Image.open(uploaded_file).convert("RGB") | |
| st.image(image, caption="Uploaded Image", use_column_width=True) | |
| # Prepare image for the model | |
| img = PILImage.create(uploaded_file) | |
| # Predict | |
| pred, pred_idx, probs = model.predict(img) | |
| # Display results | |
| st.write(f"Prediction: {pred}") | |
| st.write(f"Probability: {probs[pred_idx]:.4f}") | |
| # Optionally, display confidence as a bar chart | |
| st.bar_chart(probs.numpy()) | |