saliacoel commited on
Commit
c4853f5
·
verified ·
1 Parent(s): eb36593

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -30
app.py CHANGED
@@ -1,35 +1,28 @@
1
- import gradio as gr
2
  import spaces
3
- from detection import EyesDetection # comes from imgutils
 
 
 
 
 
 
 
 
4
 
5
- # -------------------------------------------------------------------
6
- # 1) GPU-decorated inference function
7
- @spaces.GPU(estimate=60) # ask ZeroGPU for up to 60 s of GPU
8
- def eye_detect(image):
9
- """
10
- Args
11
- ----
12
- image : PIL.Image (gradio supplies this)
13
 
14
- Returns
15
- -------
16
- masks : list[PIL.Image] – per-eye mask PNGs
17
- boxes : list[list[int]] – [x1, y1, x2, y2] per eye
18
- """
19
- global _DET
20
- if "_DET" not in globals(): # lazy-load & cache model weights
21
- _DET = EyesDetection()
22
- masks, boxes = _DET.process_image(image)
23
- return masks, boxes
24
 
25
- # -------------------------------------------------------------------
26
- # 2) API-only Gradio app (no GUI at all)
27
- with gr.Blocks() as demo:
28
- demo.api(
29
- fn=eye_detect,
30
- inputs=gr.Image(type="pil"),
31
- outputs=[gr.Gallery(label="Masks"), gr.JSON(label="Boxes")],
32
- name="eye_detect"
33
- )
34
 
35
- demo.queue(concurrency_count=1).launch()
 
1
+ import os
2
  import spaces
3
+ import gradio as gr
4
+
5
+ from detection import EyesDetection
6
+
7
+ _GLOBAL_CSS = """
8
+ .limit-height {
9
+ max-height: 55vh;
10
+ }
11
+ """
12
 
13
+ if __name__ == '__main__':
14
+ with gr.Blocks(css=_GLOBAL_CSS) as demo:
15
+ with gr.Row():
16
+ with gr.Column():
17
+ gr.HTML('<h2 style="text-align: center;">Object Detections For Anime</h2>')
18
+ gr.Markdown('This is the online demo for detection functions of '
19
+ '[imgutils.detect](https://dghs-imgutils.deepghs.org/main/api_doc/detect/index.html). '
20
+ 'You can try them yourselves with `pip install dghs-imgutils`.')
21
 
22
+ with gr.Row():
23
+ with gr.Tabs():
24
+ with gr.Tab('Eyes Detection'):
25
+ EyesDetection().make_ui()
 
 
 
 
 
 
26
 
 
 
 
 
 
 
 
 
 
27
 
28
+ demo.queue(os.cpu_count()).launch()