willco-afk commited on
Commit
9cc60d7
·
verified ·
1 Parent(s): 8cbd518

Upload app.py

Browse files

container error width measure

Files changed (1) hide show
  1. app.py +31 -12
app.py CHANGED
@@ -3,7 +3,7 @@ import os
3
  import numpy as np
4
  import tensorflow as tf
5
  from PIL import Image
6
- import io
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,21 +18,40 @@ def predict_decoration(image: Image.Image):
18
 
19
  # Make prediction
20
  prediction = model.predict(image_array)
21
- # Assuming the model outputs a binary result (decorated or undecorated)
22
  return "Decorated" if prediction[0] > 0.5 else "Undecorated"
23
 
24
  # Set up Streamlit interface
25
  st.title("Tree Decoration Predictor")
26
 
27
- # Upload image through Streamlit
28
- uploaded_image = st.file_uploader("Upload an image of a tree", type=["jpg", "jpeg", "png"])
29
 
30
- if uploaded_image:
31
- # Open and display the uploaded image
32
- image = Image.open(uploaded_image)
33
- st.image(image, caption="Uploaded Tree Image", use_column_width=True)
34
 
35
- # Predict decoration when the button is clicked
36
- if st.button("Predict Decoration"):
37
- prediction = predict_decoration(image)
38
- 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_container_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)")