Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -197,19 +197,55 @@ def predict_ripeness(audio, image, model_path):
|
|
| 197 |
else:
|
| 198 |
return "Error: Failed to process inputs. Please check the debug logs."
|
| 199 |
|
| 200 |
-
# Format the result
|
| 201 |
if ripeness is not None:
|
| 202 |
-
|
| 203 |
|
| 204 |
-
#
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
else:
|
| 212 |
-
result += "
|
| 213 |
|
| 214 |
return result
|
| 215 |
else:
|
|
@@ -250,7 +286,7 @@ def create_app(model_path):
|
|
| 250 |
submit_btn = gr.Button("Predict Ripeness", variant="primary")
|
| 251 |
|
| 252 |
with gr.Column():
|
| 253 |
-
output = gr.Textbox(label="Prediction Results", lines=
|
| 254 |
|
| 255 |
submit_btn.click(
|
| 256 |
fn=predict_fn,
|
|
@@ -259,6 +295,14 @@ def create_app(model_path):
|
|
| 259 |
)
|
| 260 |
|
| 261 |
gr.Markdown("""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
## Tips for best results
|
| 263 |
- For audio: Tap the watermelon with your knuckle and record the sound
|
| 264 |
- For image: Take a clear photo of the whole watermelon in good lighting
|
|
|
|
| 197 |
else:
|
| 198 |
return "Error: Failed to process inputs. Please check the debug logs."
|
| 199 |
|
| 200 |
+
# Format the result with a range display
|
| 201 |
if ripeness is not None:
|
| 202 |
+
ripeness_value = ripeness.item()
|
| 203 |
|
| 204 |
+
# Create a header with the numerical result
|
| 205 |
+
result = f"π Predicted Ripeness Score: {ripeness_value:.2f}/13 π\n\n"
|
| 206 |
+
|
| 207 |
+
# Add ripeness scale visualization
|
| 208 |
+
result += "Ripeness Scale based on Sugar Content:\n"
|
| 209 |
+
result += "ββββββββββββββββββββββββββββββββββ\n"
|
| 210 |
+
|
| 211 |
+
# Create the scale display
|
| 212 |
+
scale_ranges = [
|
| 213 |
+
(0, 8, "Underripe"),
|
| 214 |
+
(8, 9, "Slightly Ripe"),
|
| 215 |
+
(9, 10, "Moderately Ripe"),
|
| 216 |
+
(10, 11, "Ripe"),
|
| 217 |
+
(11, 13, "Very Ripe")
|
| 218 |
+
]
|
| 219 |
+
|
| 220 |
+
# Find which category the prediction falls into
|
| 221 |
+
user_category = None
|
| 222 |
+
for min_val, max_val, category_name in scale_ranges:
|
| 223 |
+
if min_val <= ripeness_value < max_val:
|
| 224 |
+
user_category = category_name
|
| 225 |
+
break
|
| 226 |
+
if ripeness_value >= scale_ranges[-1][0]: # Handle edge case
|
| 227 |
+
user_category = scale_ranges[-1][2]
|
| 228 |
+
|
| 229 |
+
# Display the scale with the user's result highlighted
|
| 230 |
+
for min_val, max_val, category_name in scale_ranges:
|
| 231 |
+
if category_name == user_category:
|
| 232 |
+
result += f"βΆ {min_val}-{max_val}: {category_name} β (YOUR WATERMELON)\n"
|
| 233 |
+
else:
|
| 234 |
+
result += f" {min_val}-{max_val}: {category_name}\n"
|
| 235 |
+
|
| 236 |
+
result += "ββββββββββββββββββββββββββββββββββ\n\n"
|
| 237 |
+
|
| 238 |
+
# Add assessment of the watermelon's ripeness
|
| 239 |
+
if ripeness_value < 8:
|
| 240 |
+
result += "Assessment: This watermelon is underripe. It may not have developed full flavor yet."
|
| 241 |
+
elif ripeness_value < 9:
|
| 242 |
+
result += "Assessment: This watermelon is slightly ripe. You might want to wait a few more days."
|
| 243 |
+
elif ripeness_value < 10:
|
| 244 |
+
result += "Assessment: This watermelon has moderate ripeness. It should have decent flavor."
|
| 245 |
+
elif ripeness_value < 11:
|
| 246 |
+
result += "Assessment: This watermelon is properly ripe! It should be sweet and juicy."
|
| 247 |
else:
|
| 248 |
+
result += "Assessment: This watermelon is perfectly ripe! Excellent choice for maximum sweetness and flavor."
|
| 249 |
|
| 250 |
return result
|
| 251 |
else:
|
|
|
|
| 286 |
submit_btn = gr.Button("Predict Ripeness", variant="primary")
|
| 287 |
|
| 288 |
with gr.Column():
|
| 289 |
+
output = gr.Textbox(label="Prediction Results", lines=12)
|
| 290 |
|
| 291 |
submit_btn.click(
|
| 292 |
fn=predict_fn,
|
|
|
|
| 295 |
)
|
| 296 |
|
| 297 |
gr.Markdown("""
|
| 298 |
+
## How it works
|
| 299 |
+
|
| 300 |
+
The app uses a deep learning model that combines:
|
| 301 |
+
- Audio analysis using MFCC features and LSTM neural network
|
| 302 |
+
- Image analysis using ResNet-50 convolutional neural network
|
| 303 |
+
|
| 304 |
+
The model evaluates watermelons on a scale from 0-13, where higher numbers indicate greater ripeness.
|
| 305 |
+
|
| 306 |
## Tips for best results
|
| 307 |
- For audio: Tap the watermelon with your knuckle and record the sound
|
| 308 |
- For image: Take a clear photo of the whole watermelon in good lighting
|