Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,6 +32,8 @@ def train_model(food_path, label_func):
|
|
32 |
|
33 |
# ... (previous code)
|
34 |
|
|
|
|
|
35 |
# Streamlit app
|
36 |
def main():
|
37 |
st.title("Food Classifier Streamlit App")
|
@@ -44,7 +46,10 @@ def main():
|
|
44 |
st.subheader("Training the Model")
|
45 |
food_path = Path("~/.fastai/data/food-101/food-101").expanduser()
|
46 |
if not food_path.exists():
|
47 |
-
|
|
|
|
|
|
|
48 |
label_a = st.text_input("Enter label A:", "samosa")
|
49 |
label_b = st.text_input("Enter label B:", "hot_and_sour_soup")
|
50 |
|
@@ -54,23 +59,12 @@ def main():
|
|
54 |
st.session_state.model = learn # Save the model to session state
|
55 |
st.success("Model trained successfully!")
|
56 |
|
57 |
-
|
58 |
-
st.subheader("Upload Your Own Images")
|
59 |
-
if "model" not in st.session_state:
|
60 |
-
st.warning("Please train the model first.")
|
61 |
-
else:
|
62 |
-
uploaded_files = st.file_uploader("Choose images", type=["jpg", "jpeg", "png"], accept_multiple_files=True)
|
63 |
-
|
64 |
-
if uploaded_files:
|
65 |
-
for img in uploaded_files:
|
66 |
-
img = PILImage.create(img)
|
67 |
-
label, _, probs = st.session_state.model.predict(img)
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
|
73 |
-
# ... (rest of the code remains unchanged)
|
74 |
|
75 |
|
76 |
|
|
|
32 |
|
33 |
# ... (previous code)
|
34 |
|
35 |
+
# ... (previous code)
|
36 |
+
|
37 |
# Streamlit app
|
38 |
def main():
|
39 |
st.title("Food Classifier Streamlit App")
|
|
|
46 |
st.subheader("Training the Model")
|
47 |
food_path = Path("~/.fastai/data/food-101/food-101").expanduser()
|
48 |
if not food_path.exists():
|
49 |
+
try:
|
50 |
+
food_path = untar_data(URLs.FOOD)
|
51 |
+
except FileExistsError:
|
52 |
+
st.warning("Data directory already exists. Skipping download.")
|
53 |
label_a = st.text_input("Enter label A:", "samosa")
|
54 |
label_b = st.text_input("Enter label B:", "hot_and_sour_soup")
|
55 |
|
|
|
59 |
st.session_state.model = learn # Save the model to session state
|
60 |
st.success("Model trained successfully!")
|
61 |
|
62 |
+
# ... (rest of the code remains unchanged)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
+
# Run the Streamlit app
|
65 |
+
if __name__ == "__main__":
|
66 |
+
main()
|
67 |
|
|
|
68 |
|
69 |
|
70 |
|