otmanheddouch commited on
Commit
4edcf13
·
verified ·
1 Parent(s): 4d5031e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -33
app.py CHANGED
@@ -5,32 +5,32 @@ import numpy as np
5
  import os
6
  from PIL import Image
7
 
8
-
9
  def perform(image):
10
- """Perform the task of detection"""
11
- # Predict with the model
12
- results = model(image, save=True) # predict on an image
13
- # get the saved prediction
14
- prediction_image = Image.open(os.path.join(results[0].save_dir, os.listdir(results[0].save_dir)[0]))
15
- # initialize the output list to save the bbox
16
- outputs = []
17
- # Access the results
18
- for result in results[0]:
19
- xywh = result.boxes.xyxy[0].numpy().tolist() # top-left-x, top-left-y, bottom-right-x, bottom-right-y
20
- name = result.names[result.boxes.cls.item()] # classes
21
- confs = float(result.boxes.conf) # confidence score of each box
22
- outputs.append({"xywh":xywh ,"conf":confs, "name":name})
23
- # return the image and the bbox
24
- return prediction_image, outputs
25
 
26
- def load_model(model_name:str = "yolo11n.pt"):
27
- """Model loading"""
28
- try:
29
- print(f"Loading the model {model_name}")
30
- model = YOLO(model_name)
31
- except Exception as e:
32
- print(f"Error loading the model {e}")
33
- return model
 
34
 
35
  # loading the model
36
  model = load_model()
@@ -47,12 +47,5 @@ demo = gr.Interface(
47
 
48
  # Launch the app
49
  if __name__ == "__main__":
50
- username = os.environ.get('username')
51
- password = os.environ.get('password')
52
- print(username, " ",password)
53
- demo.launch(share=True,
54
- ssr_mode=False,
55
- server_name="0.0.0.0",
56
- server_port=7860,
57
- auth=(username, password)
58
- )
 
5
  import os
6
  from PIL import Image
7
 
 
8
  def perform(image):
9
+ """Perform the task of detection"""
10
+ # Predict with the model
11
+ results = model(image, save=True) # predict on an image
12
+ # get the saved prediction
13
+ prediction_image = Image.open(os.path.join(results[0].save_dir, os.listdir(results[0].save_dir)[0]))
14
+ # initialize the output list to save the bbox
15
+ outputs = []
16
+ # Access the results
17
+ for result in results[0]:
18
+ xywh = result.boxes.xyxy[0].numpy().tolist() # top-left-x, top-left-y, bottom-right-x, bottom-right-y
19
+ name = result.names[result.boxes.cls.item()] # classes
20
+ confs = float(result.boxes.conf) # confidence score of each box
21
+ outputs.append({"xywh":xywh ,"conf":confs, "name":name})
22
+ # return the image and the bbox
23
+ return prediction_image, outputs
24
 
25
+ def load_model(model_name: str = "yolo11n.pt"):
26
+ """Model loading"""
27
+ try:
28
+ print(f"Loading the model {model_name}")
29
+ model = YOLO(model_name)
30
+ except Exception as e:
31
+ print(f"Error loading the model {e}")
32
+ return None
33
+ return model
34
 
35
  # loading the model
36
  model = load_model()
 
47
 
48
  # Launch the app
49
  if __name__ == "__main__":
50
+
51
+ demo.launch()