Nunzio commited on
Commit
94c4671
·
1 Parent(s): ed3e09d
Files changed (1) hide show
  1. app.py +32 -33
app.py CHANGED
@@ -3,39 +3,6 @@ from model.BiSeNet.build_bisenet import BiSeNet
3
  import gradio as gr
4
  from utils.imageHandling import hfImageToTensor, preprocessing
5
 
6
-
7
- def run_prediction(image: gr.Image, selected_model: str)-> tuple[torch.Tensor]:
8
- device = 'cuda' if torch.cuda.is_available() else 'cpu'
9
- image = hfImageToTensor(image, width=1024, height=512)
10
- return image, predict(image, loadModel(selected_model, device))
11
-
12
- # Gradio UI
13
- with gr.Blocks(title="🔀 BiSeNet | BiSeNetV2 Predictor") as demo:
14
- gr.Markdown("## 🧠 Image Segmentation with BiSeNet and BiSeNetV2")
15
- gr.Markdown("Upload an image and choose your preferred model for segmentation.")
16
-
17
- with gr.Row():
18
- with gr.Column():
19
- model_selector = gr.Radio(
20
- choices=["BiSeNet", "BiSeNetV2"],
21
- value="BiSeNet",
22
- label="Select model"
23
- )
24
- image_input = gr.Image(type="pil", label="Upload image")
25
- submit_btn = gr.Button("🧪 Run prediction")
26
- with gr.Column():
27
- original_display = gr.Image(label="Original image")
28
- result_display = gr.Image(label="Model prediction")
29
-
30
- submit_btn.click(
31
- fn=run_prediction,
32
- inputs=[image_input, model_selector],
33
- outputs=[original_display, result_display]
34
- )
35
-
36
- demo.launch()
37
-
38
-
39
  # %% prediction on an image
40
 
41
  def predict(inputImage: torch.Tensor, model: BiSeNet) -> torch.Tensor:
@@ -92,3 +59,35 @@ def loadBiSeNet(device: str = 'cpu') -> BiSeNet:
92
  model.eval()
93
 
94
  return model
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  import gradio as gr
4
  from utils.imageHandling import hfImageToTensor, preprocessing
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  # %% prediction on an image
7
 
8
  def predict(inputImage: torch.Tensor, model: BiSeNet) -> torch.Tensor:
 
59
  model.eval()
60
 
61
  return model
62
+
63
+
64
+ # %% Gradio interface
65
+ def run_prediction(image: gr.Image, selected_model: str)-> tuple[torch.Tensor]:
66
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
67
+ image = hfImageToTensor(image, width=1024, height=512)
68
+ return image, predict(image, loadModel(selected_model, device))
69
+
70
+ # Gradio UI
71
+ with gr.Blocks(title="🔀 BiSeNet | BiSeNetV2 Predictor") as demo:
72
+ gr.Markdown("## 🧠 Image Segmentation with BiSeNet and BiSeNetV2")
73
+ gr.Markdown("Upload an image and choose your preferred model for segmentation.")
74
+
75
+ with gr.Row():
76
+ with gr.Column():
77
+ model_selector = gr.Radio(
78
+ choices=["BiSeNet", "BiSeNetV2"],
79
+ value="BiSeNet",
80
+ label="Select model"
81
+ )
82
+ image_input = gr.Image(type="pil", label="Upload image")
83
+ submit_btn = gr.Button("🧪 Run prediction")
84
+ with gr.Column():
85
+ result_display = gr.Image(label="Model prediction")
86
+
87
+ submit_btn.click(
88
+ fn=run_prediction,
89
+ inputs=[image_input, model_selector],
90
+ outputs=[result_display]
91
+ )
92
+
93
+ demo.launch()