Spaces:
Build error
Build error
Commit
·
eeb4a26
1
Parent(s):
e3e4a01
Upload 2 files
Browse files
app.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pickle
|
| 4 |
+
import pandas as pd
|
| 5 |
+
from ultralytics import YOLO
|
| 6 |
+
import os
|
| 7 |
+
import glob
|
| 8 |
+
import cv2
|
| 9 |
+
from statistics import mode
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
letter_map={0: 'അ', 1: 'ആ', 2: 'ച', 3: 'ഇ', 4: 'ജ', 5: 'ക', 6: 'ല', 7: 'ൾ', 8: 'ണ', 9: 'ന', 10: 'പ', 11: 'ര', 12: 'ർ', 13: 'റ', 14: 'സ', 15: 'ട', 16: 'ത', 17: 'വ', 18: 'യ', 19: 'ഴ'}
|
| 13 |
+
|
| 14 |
+
st.header('Sign Detection')
|
| 15 |
+
model = YOLO(r"C:\Users\hp\OneDrive\Desktop\mini pro\mini\best.onnx",task='detect')
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def extract_frames(uploaded_file, output_folder):
|
| 20 |
+
input_name = os.path.splitext(uploaded_file.name)[0]
|
| 21 |
+
if not os.path.exists(output_folder):
|
| 22 |
+
os.makedirs(output_folder)
|
| 23 |
+
|
| 24 |
+
content = uploaded_file.getvalue()
|
| 25 |
+
|
| 26 |
+
temp_file_path = os.path.join(output_folder, "temp_video.mp4")
|
| 27 |
+
with open(temp_file_path, "wb") as temp_file:
|
| 28 |
+
temp_file.write(content)
|
| 29 |
+
|
| 30 |
+
video_capture = cv2.VideoCapture(temp_file_path)
|
| 31 |
+
frame_count = 0
|
| 32 |
+
|
| 33 |
+
while True:
|
| 34 |
+
ret, frame = video_capture.read()
|
| 35 |
+
if not ret:
|
| 36 |
+
break
|
| 37 |
+
frame_filename = os.path.join(output_folder, f"{input_name}-{frame_count:04d}.jpg")
|
| 38 |
+
cv2.imwrite(frame_filename, frame)
|
| 39 |
+
frame_count += 1
|
| 40 |
+
video_capture.release()
|
| 41 |
+
st.write(f"Extracted {frame_count} frames from uploaded video to {output_folder}")
|
| 42 |
+
os.remove(temp_file_path)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
uploaded_file = st.file_uploader("Choose a video file", type=["mp4"])
|
| 46 |
+
if uploaded_file is not None:
|
| 47 |
+
st.video(uploaded_file)
|
| 48 |
+
st.text("Uploaded Video")
|
| 49 |
+
|
| 50 |
+
if st.button("Submit"):
|
| 51 |
+
output_folder = r"C:\Users\hp\OneDrive\Desktop\mini pro\mini\output"
|
| 52 |
+
files = glob.glob(os.path.join(output_folder, '*'))
|
| 53 |
+
for file in files:
|
| 54 |
+
os.remove(file)
|
| 55 |
+
extract_frames(uploaded_file, output_folder)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
preds=[]
|
| 59 |
+
t=[]
|
| 60 |
+
cl = []
|
| 61 |
+
previous_element = None
|
| 62 |
+
word=''
|
| 63 |
+
|
| 64 |
+
for file in sorted(os.listdir(output_folder)):
|
| 65 |
+
frame=os.path.join(output_folder,file)
|
| 66 |
+
print(frame)
|
| 67 |
+
res=model.predict(frame)
|
| 68 |
+
try:
|
| 69 |
+
preds.append(int(res[0].boxes.data[0][-1]))
|
| 70 |
+
except:
|
| 71 |
+
preds.append(-1)
|
| 72 |
+
|
| 73 |
+
st.write(preds)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
if len(preds)%25:
|
| 77 |
+
a=0
|
| 78 |
+
b=a+25
|
| 79 |
+
for i in range((len(preds)//25)+1):
|
| 80 |
+
t.append(mode(preds[a:b]))
|
| 81 |
+
a,b=b,b+25
|
| 82 |
+
elif len(preds)%25:
|
| 83 |
+
a=0
|
| 84 |
+
b=a+25
|
| 85 |
+
for i in range(len(preds)//25):
|
| 86 |
+
t.append(mode(preds[a:b]))
|
| 87 |
+
a,b=b,b+25
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
for element in t:
|
| 91 |
+
if element != -1:
|
| 92 |
+
if element != previous_element:
|
| 93 |
+
cl.append(element)
|
| 94 |
+
previous_element = element
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
for i in cl:
|
| 98 |
+
word+=letter_map[i]
|
| 99 |
+
st.write(word)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
best.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dbe0feb4b15b63c6c536cf954c764ddfab61fcfdca20761f19cf0ebe4cbd4cc4
|
| 3 |
+
size 103633604
|