willco-afk commited on
Commit
0dfefb4
·
verified ·
1 Parent(s): 39ae59e

Upload app.py

Browse files

UI updated links provided download provided

Files changed (1) hide show
  1. app.py +33 -18
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 io
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
- # Upload image through Streamlit
32
- uploaded_image = st.file_uploader("Upload an image of a tree", type=["jpg", "jpeg", "png"])
33
-
34
- if uploaded_image:
35
- # Open and display the uploaded image
36
- image = Image.open(uploaded_image)
37
- st.image(image, caption="Uploaded Tree Image", use_column_width=True)
38
-
39
- # Predict decoration when the button is clicked
40
- if st.button("Predict Decoration"):
41
- prediction = predict_decoration(image)
42
- st.write(f"Prediction: {prediction}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)")