Spaces:
Sleeping
Sleeping
Upload main.py
Browse files
main.py
CHANGED
|
@@ -61,31 +61,37 @@ async def forward_to_rumas(b64_str: str, wa_id: str, task_id: str):
|
|
| 61 |
print(f"[RUMAS] β {resp.status_code}")
|
| 62 |
pretty_print_dict(body)
|
| 63 |
|
| 64 |
-
# ββ send parsed ID back to WhatsApp ββ
|
| 65 |
-
if wa_id and
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
# Remove task from active list
|
| 83 |
active_tasks.pop(task_id, None)
|
| 84 |
-
print(f"[TASK] Completed and removed task {task_id}")
|
| 85 |
elif task_id not in active_tasks:
|
| 86 |
print(f"[TASK] Ignoring response for inactive task {task_id}")
|
| 87 |
-
else:
|
| 88 |
-
print(f"[TASK] RUMAS response not successful for task {task_id}")
|
| 89 |
|
| 90 |
except Exception as e:
|
| 91 |
print(f"[RUMAS] β error while sending '{short}β¦' β", e)
|
|
|
|
| 61 |
print(f"[RUMAS] β {resp.status_code}")
|
| 62 |
pretty_print_dict(body)
|
| 63 |
|
| 64 |
+
# ββ send parsed ID back to WhatsApp or error message ββ
|
| 65 |
+
if wa_id and task_id in active_tasks:
|
| 66 |
+
if data.get("status") == "success":
|
| 67 |
+
print(f"[TASK] Sending response for active task {task_id}")
|
| 68 |
+
det = data["results"][0]["detections"][0]
|
| 69 |
+
reply = (
|
| 70 |
+
"β
*ID processed*\n"
|
| 71 |
+
f"*Name*: {det.get('name','?')} {det.get('surname','')}\n"
|
| 72 |
+
f"*ID No.*: {det.get('id_num','?')}\n"
|
| 73 |
+
f"*DOB*: {det.get('date_of_birth','?')}\n"
|
| 74 |
+
f"*Gender*: {det.get('gender','?')}\n"
|
| 75 |
+
f"*ID Type*: {det.get('id_type','?')}\n"
|
| 76 |
+
f"*Country of Birth*: {det.get('cob','?')}\n"
|
| 77 |
+
f"*Citizen*: {det.get('citizen','?')}\n"
|
| 78 |
+
f"*Citizen Status*: {det.get('citizen_status','?')}\n"
|
| 79 |
+
f"*Date Issued*: {det.get('date_issued','?')}\n"
|
| 80 |
+
f"*Age*: {det.get('age','?')}"
|
| 81 |
+
)
|
| 82 |
+
send_whatsapp_message(wa_id, reply)
|
| 83 |
+
print(f"[TASK] Completed and removed task {task_id}")
|
| 84 |
+
elif "error" in data:
|
| 85 |
+
error_msg = data["error"]
|
| 86 |
+
print(f"[TASK] RUMAS error for task {task_id}: {error_msg}")
|
| 87 |
+
send_whatsapp_message(wa_id, f"β {error_msg}")
|
| 88 |
+
else:
|
| 89 |
+
print(f"[TASK] RUMAS response not successful for task {task_id}")
|
| 90 |
+
send_whatsapp_message(wa_id, "β Sorry, we could not process your ID. Please try again with a clearer image.")
|
| 91 |
# Remove task from active list
|
| 92 |
active_tasks.pop(task_id, None)
|
|
|
|
| 93 |
elif task_id not in active_tasks:
|
| 94 |
print(f"[TASK] Ignoring response for inactive task {task_id}")
|
|
|
|
|
|
|
| 95 |
|
| 96 |
except Exception as e:
|
| 97 |
print(f"[RUMAS] β error while sending '{short}β¦' β", e)
|