Spaces:
Sleeping
Sleeping
File size: 1,984 Bytes
bb3d0a0 9c63de6 8b05948 bb3d0a0 8b05948 9c63de6 8b05948 252c8e5 8b05948 9c63de6 8b05948 bb3d0a0 9c63de6 8b05948 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import gradio as gr
import cv2
import numpy as np
from detect_people import detect_people_from_image
from table_occupancy import is_table_occupied
from face_utils import recognize_face
from db import get_table_status, log_customer_visit, get_alerts
# Gradio interface function to analyze uploaded image
def analyze_image(image):
try:
# Ensure image is in correct format (NumPy array, BGR for OpenCV)
if not isinstance(image, np.ndarray):
image = np.array(image)
if image.shape[-1] == 4: # Convert RGBA to BGR if needed
image = cv2.cvtColor(image, cv2.COLOR_RGBA2BGR)
elif image.shape[-1] == 3: # Ensure RGB is converted to BGR
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
# Run analysis functions
people = detect_people_from_image(image)
seated = is_table_occupied(image)
role = recognize_face(image)
# Log a visit to the database (adjust timestamp as needed)
import datetime
log_customer_visit(role, datetime.datetime.now(), table_id=1)
# Get table status and alerts
table_status = get_table_status()
alerts = get_alerts()
# Format output
output = (
f"People detected: {people}\n"
f"Table occupied: {seated}\n"
f"Face match: {role}\n"
f"Table status: {table_status}\n"
f"Active alerts: {alerts}"
)
return output
except Exception as e:
return f"Error processing image: {e}"
# Define Gradio interface
demo = gr.Interface(
fn=analyze_image,
inputs=gr.Image(type="numpy"), # Expect NumPy array input
outputs="text",
title="Table Occupancy and Face Detection",
description="Upload an image to detect people, table occupancy, and recognize faces."
)
# Start the Gradio app
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860, share=False) |