willco-afk commited on
Commit
9268827
·
verified ·
1 Parent(s): dae7f18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -24
app.py CHANGED
@@ -3,33 +3,25 @@ import streamlit as st
3
  import tensorflow as tf
4
  from PIL import Image
5
  import numpy as np
 
6
 
7
- # Load your Keras model from Google Drive
8
- model = tf.keras.models.load_model('/content/drive/MyDrive/your_trained_model.keras')
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # Streamlit UI
11
  st.title("Christmas Tree Classifier")
12
  st.write("Upload an image of a Christmas tree to classify it:")
13
 
14
- uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
15
-
16
- if uploaded_file is not None:
17
- # Display the uploaded image
18
- image = Image.open(uploaded_file)
19
- st.image(image, caption="Uploaded Image.", use_column_width=True)
20
- st.write("")
21
- st.write("Classifying...")
22
-
23
- # Preprocess the image
24
- image = image.resize((224, 224)) # Resize to match your model's input size
25
- image_array = np.array(image) / 255.0 # Normalize pixel values
26
- image_array = np.expand_dims(image_array, axis=0) # Add batch dimension
27
-
28
- # Make prediction
29
- prediction = model.predict(image_array)
30
-
31
- # Get predicted class
32
- predicted_class = "Decorated" if prediction[0][0] >= 0.5 else "Undecorated"
33
-
34
- # Display the prediction
35
- st.write(f"Prediction: {predicted_class}")
 
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" # Name of your .keras file
16
+ cache_dir = "./models" # Local directory to cache the model (create if it doesn't exist)
17
+ os.makedirs(cache_dir, exist_ok=True) # Create the directory if it doesn't exist
18
+ model_path = hf_hub_download(repo_id=repo_id, filename=filename, cache_dir=cache_dir)
19
+
20
+ # Load the model (this line should replace the Google Drive loading line)
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
+ # ... (rest of your Streamlit code remains the same) ...