visionNoob commited on
Commit
465faaf
·
1 Parent(s): c070ad7

Add app and sample images, track images with LFS

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.jpg filter=lfs diff=lfs merge=lfs -text
37
+ *.png filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .env
app.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import gradio as gr
3
+ import os
4
+ from dotenv import load_dotenv
5
+ from ultralytics import YOLO
6
+ import cv2
7
+ import numpy as np
8
+ from PIL import Image
9
+ from huggingface_hub import hf_hub_download
10
+
11
+ # Load environment variables
12
+ load_dotenv()
13
+
14
+ # Get model repo and filename from environment variable
15
+ MODEL_REPO = os.getenv("MODEL_REPO", "visionNoob/test_model")
16
+ MODEL_FILENAME = os.getenv("MODEL_FILENAME", "weights/best.pt")
17
+ HF_TOKEN = os.getenv("HF_TOKEN")
18
+ SECRET_KEY = os.getenv("SECRET_KEY", "changeme")
19
+
20
+ # Download model from Hugging Face Hub
21
+ model_path = hf_hub_download(
22
+ repo_id=MODEL_REPO, filename=MODEL_FILENAME, token=HF_TOKEN
23
+ )
24
+ print(f"Model downloaded to: {model_path}")
25
+ # Load YOLO model
26
+ model = YOLO(model_path)
27
+
28
+
29
+ @spaces.GPU
30
+ def predict(image):
31
+ """
32
+ Predict objects in the input image using YOLO model (YOLOv11x)
33
+ """
34
+ if image is None:
35
+ return None
36
+
37
+ # Run inference
38
+ results = model(image)
39
+
40
+ # Get the first result (assuming single image)
41
+ result = results[0]
42
+
43
+ # Draw bounding boxes on the image
44
+ annotated_image = result.plot()
45
+
46
+ # Convert BGR to RGB for display
47
+ annotated_image = cv2.cvtColor(annotated_image, cv2.COLOR_BGR2RGB)
48
+
49
+ return Image.fromarray(annotated_image)
50
+
51
+
52
+ # --- Authentication logic ---
53
+ def check_secret_key(input_key):
54
+ if input_key == SECRET_KEY:
55
+ return gr.update(visible=False), gr.update(visible=True), ""
56
+ else:
57
+ return (
58
+ gr.update(visible=True),
59
+ gr.update(visible=False),
60
+ "Incorrect password. Please try again.",
61
+ )
62
+
63
+
64
+ # Authentication components
65
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
66
+ with gr.Group(visible=True) as auth_ui:
67
+ gr.Markdown("# Authentication Required: Enter SECRET_KEY")
68
+ secret_input = gr.Textbox(
69
+ type="password", label="Enter SECRET_KEY", interactive=True
70
+ )
71
+ submit_btn = gr.Button("Confirm")
72
+ error_text = gr.Markdown(visible=False)
73
+
74
+ # Main interface (hidden by default)
75
+ with gr.Column(visible=False) as main_ui:
76
+ gr.Interface(
77
+ fn=predict,
78
+ inputs=gr.Image(type="pil", label="Upload Image"),
79
+ outputs=gr.Image(type="pil", label="Predictions"),
80
+ title="TRASH-10 Object Detection (YOLOv11x)",
81
+ examples=[
82
+ "samples/sample1.jpg",
83
+ "samples/sample2.jpg",
84
+ "samples/sample3.jpg",
85
+ "samples/sample4.jpg",
86
+ "samples/sample5.jpg",
87
+ "samples/sample6.jpg",
88
+ ],
89
+ )
90
+
91
+ def handle_secret_key(input_key):
92
+ if input_key == SECRET_KEY:
93
+ # Hide auth UI, show main, hide error
94
+ return (
95
+ gr.update(visible=False),
96
+ gr.update(visible=True),
97
+ gr.update(visible=False),
98
+ )
99
+ else:
100
+ # Show auth UI, hide main, show error
101
+ return (
102
+ gr.update(visible=True),
103
+ gr.update(visible=False),
104
+ gr.update(visible=True, value="Incorrect password. Please try again."),
105
+ )
106
+
107
+ submit_btn.click(
108
+ handle_secret_key,
109
+ inputs=secret_input,
110
+ outputs=[auth_ui, main_ui, error_text],
111
+ )
112
+
113
+ demo.launch()
samples/sample1.jpg ADDED

Git LFS Details

  • SHA256: a386e452407a9a586399688c748f14bbdefd3b998979d575d4a4be435023ffed
  • Pointer size: 131 Bytes
  • Size of remote file: 126 kB
samples/sample2.jpg ADDED

Git LFS Details

  • SHA256: 9f41f051bc4d2b048eeeed9f1bb5c0c813f64584886e0a869ea48cd2b1e7c156
  • Pointer size: 131 Bytes
  • Size of remote file: 110 kB
samples/sample3.jpg ADDED

Git LFS Details

  • SHA256: 447810bb23da0d9f591a7270cb1b00a4f0c651704c53cab47e88433123822d6e
  • Pointer size: 130 Bytes
  • Size of remote file: 95.7 kB
samples/sample4.jpg ADDED

Git LFS Details

  • SHA256: 9cbc2a8288021f929c1824e689941da6223396b59b465404d3fe0dfb5f05bcec
  • Pointer size: 130 Bytes
  • Size of remote file: 26.7 kB
samples/sample5.jpg ADDED

Git LFS Details

  • SHA256: a21d8a90040bc970b3e6d95e1226955c4e0d4debcdcd6e492b2620d2ad69ba14
  • Pointer size: 131 Bytes
  • Size of remote file: 161 kB
samples/sample6.jpg ADDED

Git LFS Details

  • SHA256: 0ea9c3b1f169d652da75985e3cf4cb6221d6a7d04fd423de5e25e93bc716a241
  • Pointer size: 130 Bytes
  • Size of remote file: 92 kB