Spaces:
Sleeping
Sleeping
Upload app.py
Browse filesUI updated links provided download provided
app.py
CHANGED
|
@@ -3,11 +3,7 @@ import os
|
|
| 3 |
import numpy as np
|
| 4 |
import tensorflow as tf
|
| 5 |
from PIL import Image
|
| 6 |
-
import
|
| 7 |
-
import warnings
|
| 8 |
-
|
| 9 |
-
# Filter warnings (done before loading model and processing)
|
| 10 |
-
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
| 11 |
|
| 12 |
# Load your pre-trained Keras model (adjust the path as needed)
|
| 13 |
MODEL_PATH = "your_trained_model.keras" # Model file location in Hugging Face Space
|
|
@@ -22,21 +18,40 @@ def predict_decoration(image: Image.Image):
|
|
| 22 |
|
| 23 |
# Make prediction
|
| 24 |
prediction = model.predict(image_array)
|
| 25 |
-
# Assuming the model outputs a binary result (decorated or undecorated)
|
| 26 |
return "Decorated" if prediction[0] > 0.5 else "Undecorated"
|
| 27 |
|
| 28 |
# Set up Streamlit interface
|
| 29 |
st.title("Tree Decoration Predictor")
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
image
|
| 37 |
-
st.
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import tensorflow as tf
|
| 5 |
from PIL import Image
|
| 6 |
+
import requests
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Load your pre-trained Keras model (adjust the path as needed)
|
| 9 |
MODEL_PATH = "your_trained_model.keras" # Model file location in Hugging Face Space
|
|
|
|
| 18 |
|
| 19 |
# Make prediction
|
| 20 |
prediction = model.predict(image_array)
|
|
|
|
| 21 |
return "Decorated" if prediction[0] > 0.5 else "Undecorated"
|
| 22 |
|
| 23 |
# Set up Streamlit interface
|
| 24 |
st.title("Tree Decoration Predictor")
|
| 25 |
|
| 26 |
+
# Create tabs for better organization
|
| 27 |
+
tab1, tab2 = st.tabs(["Upload Image", "Tree Image URLs"])
|
| 28 |
+
|
| 29 |
+
# Upload Image Tab
|
| 30 |
+
with tab1:
|
| 31 |
+
# Upload image and make prediction
|
| 32 |
+
uploaded_image = st.file_uploader("Upload an image of a tree", type=["jpg", "jpeg", "png"])
|
| 33 |
+
|
| 34 |
+
if uploaded_image:
|
| 35 |
+
image = Image.open(uploaded_image)
|
| 36 |
+
st.image(image, caption="Uploaded Tree Image", use_column_width=True)
|
| 37 |
+
|
| 38 |
+
if st.button("Predict Decoration"):
|
| 39 |
+
prediction = predict_decoration(image)
|
| 40 |
+
st.write(f"Prediction: {prediction}")
|
| 41 |
+
|
| 42 |
+
# Tree Image URLs Tab
|
| 43 |
+
with tab2:
|
| 44 |
+
# Fetch tree image URLs
|
| 45 |
+
st.write("Below is a list of tree image URLs available for testing:")
|
| 46 |
+
url = 'https://raw.githubusercontent.com/willco-afk/tree-samples/main/tree_images.txt'
|
| 47 |
+
response = requests.get(url)
|
| 48 |
+
|
| 49 |
+
if response.status_code == 200:
|
| 50 |
+
urls = response.text.splitlines()
|
| 51 |
+
for url in urls:
|
| 52 |
+
st.write(url)
|
| 53 |
+
else:
|
| 54 |
+
st.write("Failed to fetch the file.")
|
| 55 |
+
|
| 56 |
+
# Add download link here in the Tree Image URLs Tab for better context
|
| 57 |
+
st.markdown("[Download tree_images.txt](https://raw.githubusercontent.com/willco-afk/tree-samples/main/tree_images.txt)")
|