msn-enginenova21 commited on
Commit
a7ae08c
·
1 Parent(s): de85ab8

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -97
app.py DELETED
@@ -1,97 +0,0 @@
1
- import streamlit as st
2
- from PIL import Image
3
- import cv2
4
- import numpy as np
5
- import subprocess
6
- import shutil
7
- import os
8
- import torch
9
- import time
10
-
11
-
12
-
13
-
14
- def clear_detect_directory():
15
- detect_directory = "yolov5/runs/detect"
16
- if os.path.exists(detect_directory):
17
- shutil.rmtree(detect_directory)
18
- os.makedirs(detect_directory)
19
-
20
-
21
- def save_image():
22
-
23
- st.title("Hand Sign Detection")
24
- col1, col2 = st.columns(2) # 2 for two col
25
- pd_df=None
26
- with col1:
27
- genre = st.radio(
28
- "Upload Your Hand Sign",
29
- ('Browse', 'Camera'))
30
-
31
- if genre == 'Camera':
32
- uploaded_image = st.camera_input("Take a picture")
33
-
34
- else:
35
- uploaded_image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
36
-
37
- if uploaded_image is not None:
38
-
39
- # Convert the image to a format compatible with PIL and OpenCV
40
- pil_image = Image.open(uploaded_image)
41
- opencv_image = np.array(pil_image)
42
- opencv_image = cv2.cvtColor(opencv_image, cv2.COLOR_BGR2RGB)
43
-
44
- # Provide a file path to save the image
45
- upload_image_path = "processed_image.jpg"
46
- cv2.imwrite(upload_image_path, opencv_image)
47
-
48
- st.success(f"Image saved as {upload_image_path}")
49
- st.success("Processing Image...")
50
-
51
- # label of image:
52
- model = torch.hub.load('ultralytics/yolov5', 'custom', path='best.pt') # local model
53
- results = model(upload_image_path)
54
- pd_df = (results.pandas().xyxy[0])
55
-
56
- # max_confidence_name = pd_df.loc[pd_df['confidence'].idxmax(), 'name']
57
-
58
- clear_detect_directory()
59
-
60
- command = [
61
- "python",
62
- "yolov5/detect.py",
63
- "--weights", "best.pt",
64
- "--img", "416",
65
- "--conf", "0.50",
66
- "--source", upload_image_path
67
- ]
68
-
69
- process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
70
- std_out, std_err = process.communicate()
71
- if process.returncode != 0:
72
- error_message = f"Error: {std_err}"
73
- st.text(error_message)
74
-
75
-
76
-
77
-
78
- with col2:
79
- detect_image_pred = "yolov5/runs/detect/exp/processed_image.jpg"
80
- if os.path.exists(detect_image_pred):
81
- st.text("Detected Gesture")
82
- st.image(detect_image_pred, caption="Detected Image", use_column_width=True)
83
-
84
- st.text("Detection class probabilities")
85
- if pd_df is not None:
86
- st.text(pd_df)
87
- else:
88
- pass
89
- else:
90
- st.text("Detection Threshold is 60")
91
- st.text("Detection Gesture")
92
- st.text("Note: Make clean Gesture if not detected try another Gesture")
93
- st.image("Untitled_img.png")
94
-
95
-
96
-
97
- save_image()