Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -397,10 +397,41 @@ def process_image(image, user_height_cm):
|
|
| 397 |
return measurements, cv2.cvtColor(image_cv, cv2.COLOR_BGR2RGB), keypoints.tolist()
|
| 398 |
|
| 399 |
# === Save to DB ===
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 400 |
def save_to_database(measurements, image, user_height_cm, user_id):
|
| 401 |
if not user_id:
|
| 402 |
return "❌ user_id missing from URL."
|
| 403 |
-
|
| 404 |
if measurements is None or image is None:
|
| 405 |
return "⚠️ No data to save."
|
| 406 |
|
|
@@ -412,7 +443,11 @@ def save_to_database(measurements, image, user_height_cm, user_id):
|
|
| 412 |
payload = {
|
| 413 |
"imageBase64": img_str,
|
| 414 |
"heightCm": user_height_cm,
|
| 415 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
}
|
| 417 |
|
| 418 |
try:
|
|
@@ -427,6 +462,7 @@ def save_to_database(measurements, image, user_height_cm, user_id):
|
|
| 427 |
except Exception as e:
|
| 428 |
return f"⚠️ Error during save: {str(e)}"
|
| 429 |
|
|
|
|
| 430 |
# === Gradio App ===
|
| 431 |
with gr.Blocks() as demo:
|
| 432 |
gr.Markdown("# 📏 AI-Powered Body Measurement Tool")
|
|
|
|
| 397 |
return measurements, cv2.cvtColor(image_cv, cv2.COLOR_BGR2RGB), keypoints.tolist()
|
| 398 |
|
| 399 |
# === Save to DB ===
|
| 400 |
+
# def save_to_database(measurements, image, user_height_cm, user_id):
|
| 401 |
+
# if not user_id:
|
| 402 |
+
# return "❌ user_id missing from URL."
|
| 403 |
+
|
| 404 |
+
# if measurements is None or image is None:
|
| 405 |
+
# return "⚠️ No data to save."
|
| 406 |
+
|
| 407 |
+
# buffered = BytesIO()
|
| 408 |
+
# pil_image = Image.fromarray(image)
|
| 409 |
+
# pil_image.save(buffered, format="JPEG")
|
| 410 |
+
# img_str = base64.b64encode(buffered.getvalue()).decode("utf-8")
|
| 411 |
+
|
| 412 |
+
# payload = {
|
| 413 |
+
# "imageBase64": img_str,
|
| 414 |
+
# "heightCm": user_height_cm,
|
| 415 |
+
# "measurements": measurements
|
| 416 |
+
# }
|
| 417 |
+
|
| 418 |
+
# try:
|
| 419 |
+
# response = requests.post(
|
| 420 |
+
# f"https://9d68-210-212-162-140.ngrok-free.app/upload/{user_id}",
|
| 421 |
+
# json=payload
|
| 422 |
+
# )
|
| 423 |
+
# if response.status_code == 201:
|
| 424 |
+
# return "✅ Measurements and image saved to database!"
|
| 425 |
+
# else:
|
| 426 |
+
# return f"❌ Failed: {response.status_code} - {response.text}"
|
| 427 |
+
# except Exception as e:
|
| 428 |
+
# return f"⚠️ Error during save: {str(e)}"
|
| 429 |
+
|
| 430 |
+
|
| 431 |
+
|
| 432 |
def save_to_database(measurements, image, user_height_cm, user_id):
|
| 433 |
if not user_id:
|
| 434 |
return "❌ user_id missing from URL."
|
|
|
|
| 435 |
if measurements is None or image is None:
|
| 436 |
return "⚠️ No data to save."
|
| 437 |
|
|
|
|
| 443 |
payload = {
|
| 444 |
"imageBase64": img_str,
|
| 445 |
"heightCm": user_height_cm,
|
| 446 |
+
"waistCircumferenceCm": measurements.get("Waist Circumference (cm)"),
|
| 447 |
+
"hipcircumference": measurements.get("Hip Circumference (cm)"),
|
| 448 |
+
"shoulderwidth": measurements.get("Shoulder Width (cm)"),
|
| 449 |
+
"torsolength": measurements.get("Torso Length (Neck to Pelvis, cm)"),
|
| 450 |
+
"fullarmlength": measurements.get("Full Arm Length (Shoulder to Wrist, cm)"),
|
| 451 |
}
|
| 452 |
|
| 453 |
try:
|
|
|
|
| 462 |
except Exception as e:
|
| 463 |
return f"⚠️ Error during save: {str(e)}"
|
| 464 |
|
| 465 |
+
|
| 466 |
# === Gradio App ===
|
| 467 |
with gr.Blocks() as demo:
|
| 468 |
gr.Markdown("# 📏 AI-Powered Body Measurement Tool")
|