hysts HF staff commited on
Commit
e0af351
1 Parent(s): 51488de
Files changed (4) hide show
  1. README.md +1 -1
  2. app.py +19 -15
  3. requirements.txt +8 -6
  4. style.css +8 -0
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🐠
4
  colorFrom: purple
5
  colorTo: red
6
  sdk: gradio
7
- sdk_version: 3.17.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
4
  colorFrom: purple
5
  colorTo: red
6
  sdk: gradio
7
+ sdk_version: 4.31.5
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py CHANGED
@@ -5,6 +5,7 @@ import pathlib
5
  import gradio as gr
6
  import numpy as np
7
  import PIL.Image
 
8
  import torch
9
  from sahi.prediction import ObjectPrediction
10
  from sahi.utils.cv import visualize_object_predictions
@@ -20,6 +21,7 @@ model = DetaForObjectDetection.from_pretrained(MODEL_ID)
20
  model.to(device)
21
 
22
 
 
23
  @torch.inference_mode()
24
  def run(image_path: str, threshold: float) -> np.ndarray:
25
  image = PIL.Image.open(image_path)
@@ -48,20 +50,22 @@ with gr.Blocks(css="style.css") as demo:
48
  with gr.Row():
49
  with gr.Column():
50
  image = gr.Image(label="Input image", type="filepath")
51
- threshold = gr.Slider(label="Score threshold", minimum=0, maximum=1, value=0.1, step=0.01)
52
- run_button = gr.Button("Run")
53
- result = gr.Image(label="Result", type="numpy")
 
 
 
 
 
 
54
 
55
- with gr.Row():
56
- paths = sorted(pathlib.Path("images").glob("*.jpg"))
57
- gr.Examples(
58
- examples=[[path.as_posix(), 0.1] for path in paths],
59
- inputs=[image, threshold],
60
- outputs=result,
61
- fn=run,
62
- cache_examples=True,
63
- )
64
-
65
- run_button.click(fn=run, inputs=[image, threshold], outputs=result)
66
 
67
- demo.queue().launch()
 
 
5
  import gradio as gr
6
  import numpy as np
7
  import PIL.Image
8
+ import spaces
9
  import torch
10
  from sahi.prediction import ObjectPrediction
11
  from sahi.utils.cv import visualize_object_predictions
 
21
  model.to(device)
22
 
23
 
24
+ @spaces.GPU
25
  @torch.inference_mode()
26
  def run(image_path: str, threshold: float) -> np.ndarray:
27
  image = PIL.Image.open(image_path)
 
50
  with gr.Row():
51
  with gr.Column():
52
  image = gr.Image(label="Input image", type="filepath")
53
+ threshold = gr.Slider(label="Score threshold", minimum=0, maximum=1, step=0.01, value=0.1)
54
+ run_button = gr.Button()
55
+ result = gr.Image(label="Result")
56
+ gr.Examples(
57
+ examples=[[path, 0.1] for path in sorted(pathlib.Path("images").glob("*.jpg"))],
58
+ inputs=[image, threshold],
59
+ outputs=result,
60
+ fn=run,
61
+ )
62
 
63
+ run_button.click(
64
+ fn=run,
65
+ inputs=[image, threshold],
66
+ outputs=result,
67
+ api_name="predict",
68
+ )
 
 
 
 
 
69
 
70
+ if __name__ == "__main__":
71
+ demo.queue(max_size=20).launch()
requirements.txt CHANGED
@@ -1,6 +1,8 @@
1
- git+https://github.com/huggingface/transformers@59d5ede
2
- numpy==1.24.1
3
- Pillow==9.4.0
4
- sahi==0.11.11
5
- torch==1.13.1
6
- torchvision==0.14.1
 
 
 
1
+ gradio==4.31.5
2
+ numpy==1.26.4
3
+ Pillow==10.3.0
4
+ sahi==0.11.16
5
+ spaces==0.28.3
6
+ torch==2.0.1
7
+ torchvision==0.15.2
8
+ transformers==4.41.1
style.css CHANGED
@@ -1,3 +1,11 @@
1
  h1 {
2
  text-align: center;
 
 
 
 
 
 
 
 
3
  }
 
1
  h1 {
2
  text-align: center;
3
+ display: block;
4
+ }
5
+
6
+ #duplicate-button {
7
+ margin: auto;
8
+ color: #fff;
9
+ background: #1565c0;
10
+ border-radius: 100vh;
11
  }