Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import cv2, numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
# --- your imports here (mediapipe, your AU code, etc.) ---
|
| 7 |
+
# from your_code import predict_stress_from_numpy # implement this
|
| 8 |
+
|
| 9 |
+
def predict(img: Image.Image):
|
| 10 |
+
# convert PIL -> numpy (BGR) for your pipeline
|
| 11 |
+
frame = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR)
|
| 12 |
+
# score = predict_stress_from_numpy(frame) # <-- call your code
|
| 13 |
+
# For demo, return a fake response structure:
|
| 14 |
+
score = 42.0
|
| 15 |
+
label = "STRESSED" if score >= 55 else ("POSSIBLY STRESSED" if score >= 25 else "NOT STRESSED")
|
| 16 |
+
return {"stress_score": score, "label": label}
|
| 17 |
+
|
| 18 |
+
demo = gr.Interface(
|
| 19 |
+
fn=predict,
|
| 20 |
+
inputs=gr.Image(type="pil", label="Upload a face frame"),
|
| 21 |
+
outputs=gr.JSON(label="Result"),
|
| 22 |
+
title="StressDetection_V1",
|
| 23 |
+
examples=None
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
demo.launch()
|