Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ from sklearn.ensemble import RandomForestClassifier
|
|
4 |
from sklearn.preprocessing import LabelEncoder
|
5 |
from sklearn.model_selection import train_test_split, GridSearchCV
|
6 |
import gradio as gr
|
|
|
7 |
import warnings
|
8 |
warnings.filterwarnings('ignore')
|
9 |
|
@@ -265,7 +266,11 @@ with gr.Blocks(css="""
|
|
265 |
|
266 |
def predict_and_show(mood, time_of_day, hunger_level, sentiment, snack_type):
|
267 |
text, snack = predict_snack(mood, time_of_day, hunger_level, sentiment, snack_type)
|
268 |
-
image_path = f"assets/{snack
|
|
|
|
|
|
|
|
|
269 |
return text, image_path
|
270 |
|
271 |
predict_btn.click(
|
|
|
4 |
from sklearn.preprocessing import LabelEncoder
|
5 |
from sklearn.model_selection import train_test_split, GridSearchCV
|
6 |
import gradio as gr
|
7 |
+
import os
|
8 |
import warnings
|
9 |
warnings.filterwarnings('ignore')
|
10 |
|
|
|
266 |
|
267 |
def predict_and_show(mood, time_of_day, hunger_level, sentiment, snack_type):
|
268 |
text, snack = predict_snack(mood, time_of_day, hunger_level, sentiment, snack_type)
|
269 |
+
image_path = f"assets/{snack.replace(' ', '_')}.jpeg"
|
270 |
+
if not os.path.exists(image_path):
|
271 |
+
image_path = f"assets/{snack.replace(' ', '_')}.png" # Check for .png as fallback
|
272 |
+
if not os.path.exists(image_path):
|
273 |
+
image_path = "assets/placeholder.jpeg" # Final fallback
|
274 |
return text, image_path
|
275 |
|
276 |
predict_btn.click(
|