Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,28 +21,46 @@ model_path = hf_hub_download(repo_id=repo_id, filename=filename, cache_dir=cache
|
|
21 |
model = tf.keras.models.load_model(model_path)
|
22 |
|
23 |
# Streamlit UI
|
24 |
-
st.
|
25 |
-
st.write("Upload an image of a Christmas tree to classify it:")
|
26 |
|
27 |
-
|
|
|
|
|
|
|
28 |
|
29 |
-
|
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 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
40 |
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
-
#
|
45 |
-
|
|
|
|
|
|
|
46 |
|
47 |
-
|
48 |
-
st.write(
|
|
|
|
21 |
model = tf.keras.models.load_model(model_path)
|
22 |
|
23 |
# Streamlit UI
|
24 |
+
tab1, tab2 = st.tabs(["Christmas Tree Classifier", "Sample Image Links"])
|
|
|
25 |
|
26 |
+
# Tab 1: Christmas Tree Classifier
|
27 |
+
with tab1:
|
28 |
+
st.title("Christmas Tree Classifier")
|
29 |
+
st.write("Upload an image of a Christmas tree to classify it:")
|
30 |
|
31 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
if uploaded_file is not None:
|
34 |
+
# Display the uploaded image
|
35 |
+
image = Image.open(uploaded_file)
|
36 |
+
st.image(image, caption="Uploaded Image.", use_column_width=True)
|
37 |
+
st.write("")
|
38 |
+
st.write("Classifying...")
|
39 |
|
40 |
+
# Preprocess the image
|
41 |
+
image = image.resize((224, 224)) # Resize to match your model's input size
|
42 |
+
image_array = np.array(image) / 255.0 # Normalize pixel values
|
43 |
+
image_array = np.expand_dims(image_array, axis=0) # Add batch dimension
|
44 |
+
|
45 |
+
# Make prediction
|
46 |
+
prediction = model.predict(image_array)
|
47 |
+
|
48 |
+
# Get predicted class
|
49 |
+
predicted_class = "Decorated" if prediction[0][0] >= 0.5 else "Undecorated"
|
50 |
+
|
51 |
+
# Display the prediction
|
52 |
+
st.write(f"Prediction: {predicted_class}")
|
53 |
+
|
54 |
+
# Tab 2: Sample Image Links
|
55 |
+
with tab2:
|
56 |
+
st.title("Sample Image Links and Placeholder Texts")
|
57 |
|
58 |
+
# Display 50 placeholder texts (as links) for sample tree images
|
59 |
+
st.write("Here are 50 placeholder links for sample tree images:")
|
60 |
+
|
61 |
+
for i in range(1, 51):
|
62 |
+
st.write(f"[Sample Tree Image {i}](https://www.example.com/sample-tree-image-{i})")
|
63 |
|
64 |
+
st.write("\nAdditional Links:")
|
65 |
+
st.write("[View sample images here](https://www.example.com/sample-images)")
|
66 |
+
st.write("[Download sample images here](https://www.example.com/download-sample-images)")
|