Update app.py
Browse files
app.py
CHANGED
|
@@ -82,61 +82,41 @@ def generate_pdf(info, advice, risk_score, risk_level, flags, conditions, lang,
|
|
| 82 |
pdf.output(path)
|
| 83 |
return path
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
# Output summary
|
| 122 |
-
result = (
|
| 123 |
-
f"π½οΈ Food: {display_name}\n"
|
| 124 |
-
f"π Ethnicity: {info['ethnicity']}\n"
|
| 125 |
-
f"π₯¦ Ingredients: {info['ingredients']}\n"
|
| 126 |
-
f"π₯ Calories: {info['calories']} kcal\n"
|
| 127 |
-
f"π Carbs: {info['carbs']}g\n"
|
| 128 |
-
f"π₯© Protein: {info['protein']}g\n"
|
| 129 |
-
f"π§ Fat: {info['fat']}g\n"
|
| 130 |
-
f"π± Diet Type: {info['diet_type']}\n"
|
| 131 |
-
f"π Substitute: {info.get('substitute', 'None')}\n\n"
|
| 132 |
-
f"π Confidence: {confidence}%\n"
|
| 133 |
-
f"π Risk Score: {risk_score}% ({risk_level})\n"
|
| 134 |
-
f"β οΈ Risk Factors: {', '.join(flags) if flags else 'None'}\n"
|
| 135 |
-
f"β
Advice: {advice}\n\n"
|
| 136 |
-
f"π *Generated by HoodHealth Pro+.*"
|
| 137 |
-
)
|
| 138 |
-
|
| 139 |
-
return result, audio_path, f"π£οΈ Language: {language}", pdf_path
|
| 140 |
|
| 141 |
# Gradio interface
|
| 142 |
interface = gr.Interface(
|
|
|
|
| 82 |
pdf.output(path)
|
| 83 |
return path
|
| 84 |
|
| 85 |
+
def classify_food(image):
|
| 86 |
+
try:
|
| 87 |
+
# Convert to grayscale since model expects 1 channel
|
| 88 |
+
image = image.convert("L").resize((225, 225)) # "L" = grayscale
|
| 89 |
+
img = tf.keras.preprocessing.image.img_to_array(image)
|
| 90 |
+
|
| 91 |
+
# Ensure shape is (225, 225, 1)
|
| 92 |
+
if img.shape[-1] != 1:
|
| 93 |
+
img = np.expand_dims(img, axis=-1)
|
| 94 |
+
|
| 95 |
+
# Preprocess for EfficientNet
|
| 96 |
+
img = efficientnet_preprocess(img)
|
| 97 |
+
img = np.expand_dims(img, axis=0)
|
| 98 |
+
|
| 99 |
+
# Predict
|
| 100 |
+
preds = model.predict(img)
|
| 101 |
+
pred_class = np.argmax(preds[0])
|
| 102 |
+
confidence = float(np.max(preds[0]))
|
| 103 |
+
|
| 104 |
+
food_name = class_names[pred_class]
|
| 105 |
+
food_details = food_info[food_name]
|
| 106 |
+
|
| 107 |
+
result = f"π½οΈ Food: {food_name}\n"
|
| 108 |
+
result += f"π Ethnicity: {food_details['Ethnicity']}\n"
|
| 109 |
+
result += f"π₯¦ Ingredients: {', '.join(food_details['Ingredients'])}\n"
|
| 110 |
+
result += f"π₯ Nutrients: {food_details['Nutrients']}\n"
|
| 111 |
+
result += f"β€οΈ Health Advice: {food_details['Health_Advice']}\n"
|
| 112 |
+
result += f"π± Diet Type: {food_details['Diet_Type']}\n"
|
| 113 |
+
result += f"π Confidence: {confidence:.2f}"
|
| 114 |
+
|
| 115 |
+
return result
|
| 116 |
+
|
| 117 |
+
except Exception as e:
|
| 118 |
+
return f"Error during classification: {str(e)}"
|
| 119 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
# Gradio interface
|
| 122 |
interface = gr.Interface(
|