Delete app.py
Browse files
app.py
DELETED
@@ -1,48 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
import streamlit as st
|
3 |
-
import tensorflow as tf
|
4 |
-
from PIL import Image
|
5 |
-
import numpy as np
|
6 |
-
from huggingface_hub import login, hf_hub_download
|
7 |
-
|
8 |
-
# Authenticate with Hugging Face token (if available)
|
9 |
-
hf_token = os.environ.get("HF_TOKEN")
|
10 |
-
if hf_token:
|
11 |
-
login(token=hf_token)
|
12 |
-
|
13 |
-
# Download and load the model from the Hugging Face Hub
|
14 |
-
repo_id = os.environ.get("MODEL_ID", "willco-afk/tree-test-x") # Get repo ID from secret or default
|
15 |
-
filename = "your_trained_model.keras" # Updated filename
|
16 |
-
cache_dir = "./models" # Local directory to cache the model
|
17 |
-
os.makedirs(cache_dir, exist_ok=True)
|
18 |
-
model_path = hf_hub_download(repo_id=repo_id, filename=filename, cache_dir=cache_dir)
|
19 |
-
|
20 |
-
# Load the model
|
21 |
-
model = tf.keras.models.load_model(model_path)
|
22 |
-
|
23 |
-
# Streamlit UI
|
24 |
-
st.title("Christmas Tree Classifier")
|
25 |
-
st.write("Upload an image of a Christmas tree to classify it:")
|
26 |
-
|
27 |
-
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
28 |
-
|
29 |
-
if uploaded_file is not None:
|
30 |
-
# Display the uploaded image
|
31 |
-
image = Image.open(uploaded_file)
|
32 |
-
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
33 |
-
st.write("")
|
34 |
-
st.write("Classifying...")
|
35 |
-
|
36 |
-
# Preprocess the image
|
37 |
-
image = image.resize((224, 224)) # Resize to match your model's input size
|
38 |
-
image_array = np.array(image) / 255.0 # Normalize pixel values
|
39 |
-
image_array = np.expand_dims(image_array, axis=0) # Add batch dimension
|
40 |
-
|
41 |
-
# Make prediction
|
42 |
-
prediction = model.predict(image_array)
|
43 |
-
|
44 |
-
# Get predicted class
|
45 |
-
predicted_class = "Decorated" if prediction[0][0] >= 0.5 else "Undecorated"
|
46 |
-
|
47 |
-
# Display the prediction
|
48 |
-
st.write(f"Prediction: {predicted_class}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|