Spaces:
Sleeping
Sleeping
Commit ·
bc1b5b3
1
Parent(s): 2f09e2a
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,60 +20,60 @@ def save_image():
|
|
| 20 |
st.title("Hand Sign Detection")
|
| 21 |
col1, col2 = st.columns(2) # 2 for two col
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
else:
|
| 32 |
-
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 33 |
-
|
| 34 |
-
if uploaded_image is not None:
|
| 35 |
-
|
| 36 |
-
# Convert the image to a format compatible with PIL and OpenCV
|
| 37 |
-
pil_image = Image.open(uploaded_image)
|
| 38 |
-
opencv_image = np.array(pil_image)
|
| 39 |
-
opencv_image = cv2.cvtColor(opencv_image, cv2.COLOR_BGR2RGB)
|
| 40 |
-
|
| 41 |
-
# Provide a file path to save the image
|
| 42 |
-
upload_image_path = "processed_image.jpg"
|
| 43 |
-
cv2.imwrite(upload_image_path, opencv_image)
|
| 44 |
-
|
| 45 |
-
# calling
|
| 46 |
-
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt') # local model
|
| 47 |
-
results = model(upload_image_path)
|
| 48 |
-
st.success(f"Image saved as {upload_image_path} ")
|
| 49 |
-
|
| 50 |
-
command = [
|
| 51 |
-
"python",
|
| 52 |
-
"yolov5/detect.py",
|
| 53 |
-
"--weights", "best.pt",
|
| 54 |
-
"--img", "416",
|
| 55 |
-
"--conf", "0.56",
|
| 56 |
-
"--source", upload_image_path
|
| 57 |
-
]
|
| 58 |
-
|
| 59 |
-
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
| 60 |
-
std_out, std_err = process.communicate()
|
| 61 |
-
if process.returncode != 0:
|
| 62 |
-
error_message = f"Error: {std_err}"
|
| 63 |
-
st.text(error_message)
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
with col2:
|
| 67 |
-
detect_image_pred = "yolov5/runs/detect/exp/processed_image.jpg"
|
| 68 |
-
if os.path.exists(detect_image_pred):
|
| 69 |
-
st.text("Operation in progress. Please wait....")
|
| 70 |
-
st.image(detect_image_pred, caption="Detected Image", use_column_width=True)
|
| 71 |
-
|
| 72 |
-
st.text("Detection Output:")
|
| 73 |
-
st.text(results.pandas().xyxy[0])
|
| 74 |
else:
|
| 75 |
-
st.
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
|
| 79 |
|
|
|
|
| 20 |
st.title("Hand Sign Detection")
|
| 21 |
col1, col2 = st.columns(2) # 2 for two col
|
| 22 |
|
| 23 |
+
with col1:
|
| 24 |
+
genre = st.radio(
|
| 25 |
+
"Upload Your Hand Sign",
|
| 26 |
+
('Browse', 'Camera'))
|
| 27 |
+
|
| 28 |
+
if genre == 'Camera':
|
| 29 |
+
uploaded_image = st.camera_input("Take a picture")
|
| 30 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
else:
|
| 32 |
+
uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
| 33 |
+
|
| 34 |
+
if uploaded_image is not None:
|
| 35 |
+
|
| 36 |
+
# Convert the image to a format compatible with PIL and OpenCV
|
| 37 |
+
pil_image = Image.open(uploaded_image)
|
| 38 |
+
opencv_image = np.array(pil_image)
|
| 39 |
+
opencv_image = cv2.cvtColor(opencv_image, cv2.COLOR_BGR2RGB)
|
| 40 |
+
|
| 41 |
+
# Provide a file path to save the image
|
| 42 |
+
upload_image_path = "processed_image.jpg"
|
| 43 |
+
cv2.imwrite(upload_image_path, opencv_image)
|
| 44 |
+
|
| 45 |
+
# calling
|
| 46 |
+
model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt') # local model
|
| 47 |
+
results = model(upload_image_path)
|
| 48 |
+
st.success(f"Image saved as {upload_image_path} ")
|
| 49 |
+
|
| 50 |
+
command = [
|
| 51 |
+
"python",
|
| 52 |
+
"yolov5/detect.py",
|
| 53 |
+
"--weights", "best.pt",
|
| 54 |
+
"--img", "416",
|
| 55 |
+
"--conf", "0.56",
|
| 56 |
+
"--source", upload_image_path
|
| 57 |
+
]
|
| 58 |
+
|
| 59 |
+
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
| 60 |
+
std_out, std_err = process.communicate()
|
| 61 |
+
if process.returncode != 0:
|
| 62 |
+
error_message = f"Error: {std_err}"
|
| 63 |
+
st.text(error_message)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
with col2:
|
| 67 |
+
detect_image_pred = "yolov5/runs/detect/exp/processed_image.jpg"
|
| 68 |
+
if os.path.exists(detect_image_pred):
|
| 69 |
+
st.text("Operation in progress. Please wait....")
|
| 70 |
+
st.image(detect_image_pred, caption="Detected Image", use_column_width=True)
|
| 71 |
+
|
| 72 |
+
st.text("Detection Output:")
|
| 73 |
+
st.text(results.pandas().xyxy[0])
|
| 74 |
+
else:
|
| 75 |
+
st.text("Detection Threshold is 60")
|
| 76 |
+
|
| 77 |
|
| 78 |
|
| 79 |
|