chihq commited on
Commit
2ee1270
Β·
1 Parent(s): b6d9884

Add Gradio UI at /ui for testing

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -2
  2. inference_server.py +29 -0
Dockerfile CHANGED
@@ -5,7 +5,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
5
  libsm6 libxext6 libxrender1 \
6
  && rm -rf /var/lib/apt/lists/*
7
 
8
- RUN pip install --no-cache-dir fastapi uvicorn mediapipe pillow supervision
9
 
10
  RUN useradd -m -u 1000 user
11
  USER user
@@ -21,5 +21,4 @@ ENV MEDIAPIPE_MODEL_PATH=/home/user/app/models/hand_landmarker.task
21
 
22
  EXPOSE 7860
23
 
24
- # Force rebuild v2
25
  CMD ["uvicorn", "inference_server:app", "--host", "0.0.0.0", "--port", "7860"]
 
5
  libsm6 libxext6 libxrender1 \
6
  && rm -rf /var/lib/apt/lists/*
7
 
8
+ RUN pip install --no-cache-dir fastapi uvicorn mediapipe pillow supervision gradio
9
 
10
  RUN useradd -m -u 1000 user
11
  USER user
 
21
 
22
  EXPOSE 7860
23
 
 
24
  CMD ["uvicorn", "inference_server:app", "--host", "0.0.0.0", "--port", "7860"]
inference_server.py CHANGED
@@ -12,6 +12,7 @@ from PIL import Image as _PILImage, ImageDraw as _PILDraw, ImageFont as _PILFont
12
  import mediapipe as mp
13
  from mediapipe.tasks import python as _mp_python
14
  from mediapipe.tasks.python import vision as _mp_vision
 
15
 
16
  WEIGHTS_PATH = os.getenv(
17
  "WEIGHTS_PATH",
@@ -674,3 +675,31 @@ def root():
674
  @app.get("/health")
675
  def health():
676
  return {"status": "ok"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  import mediapipe as mp
13
  from mediapipe.tasks import python as _mp_python
14
  from mediapipe.tasks.python import vision as _mp_vision
15
+ import gradio as gr
16
 
17
  WEIGHTS_PATH = os.getenv(
18
  "WEIGHTS_PATH",
 
675
  @app.get("/health")
676
  def health():
677
  return {"status": "ok"}
678
+
679
+
680
+ # ── Gradio UI ──────────────────────────────────────────────────────────────────
681
+ def gradio_annotate(image: np.ndarray, confidence: float) -> np.ndarray:
682
+ """Gradio wrapper for annotate function."""
683
+ if image is None:
684
+ return None
685
+ # Convert RGB (Gradio) to BGR (OpenCV)
686
+ image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
687
+ result = annotate(image_bgr, conf=confidence)
688
+ # Convert back to RGB for Gradio
689
+ return cv2.cvtColor(result, cv2.COLOR_BGR2RGB)
690
+
691
+
692
+ demo = gr.Interface(
693
+ fn=gradio_annotate,
694
+ inputs=[
695
+ gr.Image(label="αΊ’nh bΓ n tay", type="numpy"),
696
+ gr.Slider(0.1, 1.0, value=0.4, step=0.05, label="Confidence")
697
+ ],
698
+ outputs=gr.Image(label="KαΊΏt quαΊ£ phΓ’n tΓ­ch"),
699
+ title="πŸ– Menhso - PhΓ’n tΓ­ch đường chỉ tay",
700
+ description="Upload αΊ£nh bΓ n tay để phΓ‘t hiện cΓ‘c đường chỉ tay (head, life, love) vΓ  landmarks.",
701
+ examples=[],
702
+ allow_flagging="never"
703
+ )
704
+
705
+ app = gr.mount_gradio_app(app, demo, path="/ui")