karthikmn commited on
Commit
4b2503e
·
verified ·
1 Parent(s): 8995bfc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -11
app.py CHANGED
@@ -5,8 +5,7 @@ import cv2
5
  import numpy as np
6
  import tempfile
7
 
8
- # List of unusual labels to detect
9
- unusual_labels = ['weapon', 'fighting', 'suspicious_activity'] # Extend as needed
10
 
11
  def yolo_inference(input_type, image, video, model_id, conf_threshold, iou_threshold, max_detection):
12
  unusual_detected = False
@@ -43,7 +42,6 @@ def yolo_inference(input_type, image, video, model_id, conf_threshold, iou_thres
43
  image_array = r.plot()
44
  annotated_image = Image.fromarray(image_array[..., ::-1])
45
 
46
- # Get detected object labels
47
  for label in r.names:
48
  detected_objects.append(label)
49
  if label in unusual_labels:
@@ -125,12 +123,9 @@ def yolo_inference(input_type, image, video, model_id, conf_threshold, iou_thres
125
  with gr.Blocks() as app:
126
  with gr.Sidebar():
127
  gr.Markdown("# Inference Provider")
128
- gr.Markdown(
129
- "This Space showcases the facebook/detr-resnet-50 model, "
130
- "served by the hf-inference API. Sign in with your Hugging Face account to use this API."
131
- )
132
- button = gr.LoginButton("Sign in")
133
- gr.load("models/facebook/detr-resnet-50", accept_token=button, provider="hf-inference")
134
 
135
  gr.Markdown("# Yolo11: Object Detection, Instance Segmentation, Pose/Keypoints, Oriented Detection, Classification")
136
  gr.Markdown("Upload image(s) or video(s) for inference using the latest Ultralytics YOLO11 models.")
@@ -166,7 +161,6 @@ with gr.Blocks() as app:
166
  unusual_detected_flag = gr.Textbox(label="Unusual Detected Flag", visible=True)
167
  gr.DeepLinkButton()
168
 
169
- # Toggle visibility based on input type
170
  input_type.change(
171
  fn=lambda t: [
172
  gr.update(visible=(t == "Image")),
@@ -178,7 +172,6 @@ with gr.Blocks() as app:
178
  outputs=[image, video, output_image, output_video]
179
  )
180
 
181
- # Run inference on button click
182
  infer_button.click(
183
  fn=yolo_inference,
184
  inputs=[input_type, image, video, model_id, conf_threshold, iou_threshold, max_detection],
 
5
  import numpy as np
6
  import tempfile
7
 
8
+ unusual_labels = ['weapon', 'fighting', 'suspicious_activity'] # Example unusual labels
 
9
 
10
  def yolo_inference(input_type, image, video, model_id, conf_threshold, iou_threshold, max_detection):
11
  unusual_detected = False
 
42
  image_array = r.plot()
43
  annotated_image = Image.fromarray(image_array[..., ::-1])
44
 
 
45
  for label in r.names:
46
  detected_objects.append(label)
47
  if label in unusual_labels:
 
123
  with gr.Blocks() as app:
124
  with gr.Sidebar():
125
  gr.Markdown("# Inference Provider")
126
+ gr.Markdown("This Space showcases the facebook/detr-resnet-50 model, served by the hf-inference API.")
127
+ # Note: removed LoginButton and accept_token usage here
128
+ gr.load("models/facebook/detr-resnet-50", provider="hf-inference")
 
 
 
129
 
130
  gr.Markdown("# Yolo11: Object Detection, Instance Segmentation, Pose/Keypoints, Oriented Detection, Classification")
131
  gr.Markdown("Upload image(s) or video(s) for inference using the latest Ultralytics YOLO11 models.")
 
161
  unusual_detected_flag = gr.Textbox(label="Unusual Detected Flag", visible=True)
162
  gr.DeepLinkButton()
163
 
 
164
  input_type.change(
165
  fn=lambda t: [
166
  gr.update(visible=(t == "Image")),
 
172
  outputs=[image, video, output_image, output_video]
173
  )
174
 
 
175
  infer_button.click(
176
  fn=yolo_inference,
177
  inputs=[input_type, image, video, model_id, conf_threshold, iou_threshold, max_detection],