vashu2425 commited on
Commit
bc4ba77
·
verified ·
1 Parent(s): d943a28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -12
app.py CHANGED
@@ -27,9 +27,6 @@ CLASS_NAMES = [
27
  'tacos', 'takoyaki', 'tiramisu', 'tuna_tartare', 'waffles'
28
  ]
29
 
30
-
31
-
32
- # Define the function to predict the image
33
  # Define the function to predict the image
34
  def predict_image(img_path):
35
  # Load and preprocess the image
@@ -49,25 +46,57 @@ def predict_image(img_path):
49
  return predicted_class
50
 
51
 
52
-
53
  # Streamlit UI components
54
- st.title("Food-101 Classification Model")
55
- st.write("Upload an image of food to predict its class.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  # Upload image
58
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
59
 
60
  if uploaded_file is not None:
61
- # Display the uploaded image
62
- st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
63
 
64
  # Save the image temporarily
65
  img_path = "uploaded_image.jpg"
66
  with open(img_path, "wb") as f:
67
  f.write(uploaded_file.getbuffer())
68
 
69
- # Make prediction
70
- predicted_class = predict_image(img_path)
 
 
 
 
 
 
 
 
 
71
 
72
- # Display the predicted class
73
- st.write(f"Predicted Class: {predicted_class}")
 
27
  'tacos', 'takoyaki', 'tiramisu', 'tuna_tartare', 'waffles'
28
  ]
29
 
 
 
 
30
  # Define the function to predict the image
31
  def predict_image(img_path):
32
  # Load and preprocess the image
 
46
  return predicted_class
47
 
48
 
 
49
  # Streamlit UI components
50
+ st.set_page_config(page_title="Food-101 Classification", page_icon="🍕", layout="wide")
51
+ st.markdown("""
52
+ <style>
53
+ .stApp {
54
+ background-color: #f0f8ff;
55
+ }
56
+ .stButton>button {
57
+ background-color: #4CAF50;
58
+ color: white;
59
+ padding: 10px 20px;
60
+ border-radius: 10px;
61
+ font-size: 16px;
62
+ }
63
+ .stFileUploader>label {
64
+ color: #4CAF50;
65
+ }
66
+ .stImage>img {
67
+ border-radius: 10px;
68
+ box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.1);
69
+ }
70
+ </style>
71
+ """, unsafe_allow_html=True)
72
+
73
+ # Title
74
+ st.title("🍕 Food-101 Classification Model")
75
+ st.subheader("Upload an image of food to predict its class. 🍽️")
76
 
77
  # Upload image
78
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
79
 
80
  if uploaded_file is not None:
81
+ # Display the uploaded image with a transition effect
82
+ st.image(uploaded_file, caption="Uploaded Image", use_column_width=True, width=500)
83
 
84
  # Save the image temporarily
85
  img_path = "uploaded_image.jpg"
86
  with open(img_path, "wb") as f:
87
  f.write(uploaded_file.getbuffer())
88
 
89
+ # Show the processing animation
90
+ with st.spinner("Classifying the image... Please wait. 🕒"):
91
+ # Make prediction
92
+ predicted_class = predict_image(img_path)
93
+
94
+ # Display the predicted class with a colorful box
95
+ st.markdown(f"""
96
+ <div style="padding: 10px; border-radius: 10px; background-color: #ffeb3b; color: #0f4b5f; text-align: center; font-size: 20px;">
97
+ <strong>Predicted Class: {predicted_class.capitalize()} 🥳</strong>
98
+ </div>
99
+ """, unsafe_allow_html=True)
100
 
101
+ # Show an icon with a success message
102
+ st.balloons()