Spaces:
Build error
Build error
Update pages/Video Upload.py
Browse files- pages/Video Upload.py +184 -126
pages/Video Upload.py
CHANGED
|
@@ -1,129 +1,187 @@
|
|
| 1 |
-
import logging
|
| 2 |
-
import queue
|
| 3 |
-
from collections import deque
|
| 4 |
-
from concurrent.futures import ThreadPoolExecutor
|
| 5 |
-
|
| 6 |
import streamlit as st
|
| 7 |
-
from
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
st.warning("Please upload a video file for prediction.")
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
inference_thread.start()
|
| 90 |
-
|
| 91 |
-
text_output = st.empty()
|
| 92 |
-
|
| 93 |
-
if st.button("Predict"):
|
| 94 |
-
import tempfile
|
| 95 |
-
tfile = tempfile.NamedTemporaryFile(delete=False)
|
| 96 |
-
tfile.write(video_bytes)
|
| 97 |
-
cap = cv2.VideoCapture(tfile.name)
|
| 98 |
-
|
| 99 |
-
gestures = []
|
| 100 |
-
frames = []
|
| 101 |
-
batch_size = 32
|
| 102 |
-
|
| 103 |
-
def process_frames(batch):
|
| 104 |
-
process_batch(inference_thread, batch, gestures)
|
| 105 |
-
|
| 106 |
-
with ThreadPoolExecutor() as executor:
|
| 107 |
-
while cap.isOpened():
|
| 108 |
-
ret, frame = cap.read()
|
| 109 |
-
if not ret:
|
| 110 |
-
break
|
| 111 |
-
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 112 |
-
frames.append(frame)
|
| 113 |
-
if len(frames) == batch_size:
|
| 114 |
-
executor.submit(process_frames, frames)
|
| 115 |
-
frames = []
|
| 116 |
-
|
| 117 |
-
if frames:
|
| 118 |
-
executor.submit(process_frames, frames)
|
| 119 |
-
|
| 120 |
-
cap.release()
|
| 121 |
-
text_output.markdown(f'<p style="font-size:20px"> Gestures in video: {" ".join(gestures)}</p>',
|
| 122 |
-
unsafe_allow_html=True)
|
| 123 |
-
st.text(correct_text_gpt3(" ".join(gestures)))
|
| 124 |
-
|
| 125 |
-
print(gestures)
|
| 126 |
-
|
| 127 |
-
if __name__ == "__main__":
|
| 128 |
-
logging.basicConfig(level=logging.INFO)
|
| 129 |
-
main("configs/config.json")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Page config
|
| 6 |
+
st.set_page_config(
|
| 7 |
+
page_title="GestureGuru",
|
| 8 |
+
page_icon="🤖",
|
| 9 |
+
layout="wide",
|
| 10 |
+
initial_sidebar_state="expanded"
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
# --- Custom Style ---
|
| 14 |
+
st.markdown("""
|
| 15 |
+
<style>
|
| 16 |
+
body {
|
| 17 |
+
background-image: url('https://images.unsplash.com/photo-1498050108023-c5249f4df085?auto=format&fit=crop&w=1920&q=80');
|
| 18 |
+
background-size: cover;
|
| 19 |
+
background-attachment: fixed;
|
| 20 |
+
background-position: center;
|
| 21 |
+
font-family: 'Segoe UI', sans-serif;
|
| 22 |
+
color: #222;
|
| 23 |
+
animation: fade-in 2s ease-out;
|
| 24 |
+
}
|
| 25 |
+
.sidebar .sidebar-content {
|
| 26 |
+
background-color: rgba(255, 255, 255, 0.8);
|
| 27 |
+
padding: 1rem;
|
| 28 |
+
border-radius: 16px;
|
| 29 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
| 30 |
+
backdrop-filter: blur(8px);
|
| 31 |
+
}
|
| 32 |
+
.hero {
|
| 33 |
+
text-align: center;
|
| 34 |
+
padding: 5rem 2rem;
|
| 35 |
+
background: linear-gradient(135deg, #8e2de2, #4a00e0);
|
| 36 |
+
border-radius: 24px;
|
| 37 |
+
color: white;
|
| 38 |
+
margin-bottom: 3rem;
|
| 39 |
+
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
|
| 40 |
+
animation: fade-in 2s ease-out;
|
| 41 |
+
position: relative;
|
| 42 |
+
}
|
| 43 |
+
.hero h1 {
|
| 44 |
+
font-size: 3.75em;
|
| 45 |
+
font-weight: 700;
|
| 46 |
+
margin-bottom: 0.3em;
|
| 47 |
+
animation: glow-text 2s infinite alternate;
|
| 48 |
+
}
|
| 49 |
+
.hero p {
|
| 50 |
+
font-size: 1.3em;
|
| 51 |
+
font-weight: 300;
|
| 52 |
+
margin-top: 0.5em;
|
| 53 |
+
animation: slide-in-bottom 1.2s ease-out;
|
| 54 |
+
}
|
| 55 |
+
.hero img.logo {
|
| 56 |
+
width: 120px;
|
| 57 |
+
position: absolute;
|
| 58 |
+
top: 20px;
|
| 59 |
+
left: 20px;
|
| 60 |
+
border-radius: 50%;
|
| 61 |
+
border: 2px solid white;
|
| 62 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.4);
|
| 63 |
+
}
|
| 64 |
+
.section {
|
| 65 |
+
background: rgba(255, 255, 255, 0.95);
|
| 66 |
+
border-radius: 20px;
|
| 67 |
+
padding: 2.5rem;
|
| 68 |
+
margin-bottom: 2.5rem;
|
| 69 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
|
| 70 |
+
backdrop-filter: blur(4px);
|
| 71 |
+
animation: fade-in-up 1s ease-out;
|
| 72 |
+
}
|
| 73 |
+
.upload-section {
|
| 74 |
+
background: linear-gradient(to right, #00c6ff, #0072ff);
|
| 75 |
+
color: white;
|
| 76 |
+
padding: 2rem;
|
| 77 |
+
border-radius: 20px;
|
| 78 |
+
margin-bottom: 2rem;
|
| 79 |
+
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
|
| 80 |
+
animation: fade-in-up 1s ease-out;
|
| 81 |
+
}
|
| 82 |
+
.upload-section h3 {
|
| 83 |
+
color: white;
|
| 84 |
+
}
|
| 85 |
+
h3 {
|
| 86 |
+
font-size: 1.8rem;
|
| 87 |
+
color: #2e2e2e;
|
| 88 |
+
margin-bottom: 1rem;
|
| 89 |
+
}
|
| 90 |
+
ul, ol {
|
| 91 |
+
font-size: 1.1em;
|
| 92 |
+
line-height: 1.6;
|
| 93 |
+
color: #444;
|
| 94 |
+
}
|
| 95 |
+
.contact-block {
|
| 96 |
+
text-align: center;
|
| 97 |
+
padding: 3rem;
|
| 98 |
+
border-radius: 20px;
|
| 99 |
+
background: linear-gradient(to right, #ff6a00, #ee0979);
|
| 100 |
+
color: white;
|
| 101 |
+
margin-top: 3rem;
|
| 102 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
|
| 103 |
+
animation: fade-in 2s ease-out;
|
| 104 |
+
}
|
| 105 |
+
.contact-block a {
|
| 106 |
+
color: #fff;
|
| 107 |
+
text-decoration: underline;
|
| 108 |
+
}
|
| 109 |
+
@keyframes fade-in {
|
| 110 |
+
from { opacity: 0; }
|
| 111 |
+
to { opacity: 1; }
|
| 112 |
+
}
|
| 113 |
+
@keyframes fade-in-up {
|
| 114 |
+
from { opacity: 0; transform: translateY(30px); }
|
| 115 |
+
to { opacity: 1; transform: translateY(0); }
|
| 116 |
+
}
|
| 117 |
+
@keyframes slide-in-top {
|
| 118 |
+
0% { transform: translateY(-100px); opacity: 0; }
|
| 119 |
+
100% { transform: translateY(0); opacity: 1; }
|
| 120 |
+
}
|
| 121 |
+
@keyframes slide-in-bottom {
|
| 122 |
+
0% { transform: translateY(100px); opacity: 0; }
|
| 123 |
+
100% { transform: translateY(0); opacity: 1; }
|
| 124 |
+
}
|
| 125 |
+
@keyframes glow-text {
|
| 126 |
+
from { text-shadow: 0 0 5px #fff, 0 0 10px #bca7ff, 0 0 20px #7e57ff; }
|
| 127 |
+
to { text-shadow: 0 0 10px #fff, 0 0 20px #b388ff, 0 0 30px #7e57ff; }
|
| 128 |
+
}
|
| 129 |
+
</style>
|
| 130 |
+
""", unsafe_allow_html=True)
|
| 131 |
+
|
| 132 |
+
# --- Hero Section ---
|
| 133 |
+
st.markdown("""
|
| 134 |
+
<div class="hero">
|
| 135 |
+
<img src="https://cdn-icons-png.flaticon.com/512/3062/3062634.png" class="logo" alt="logo">
|
| 136 |
+
<h1>GestureGuru</h1>
|
| 137 |
+
<p>AI for Sign Language Understanding & Accessibility</p>
|
| 138 |
+
</div>
|
| 139 |
+
""", unsafe_allow_html=True)
|
| 140 |
+
|
| 141 |
+
# --- Features ---
|
| 142 |
+
st.markdown("""
|
| 143 |
+
<div class="section">
|
| 144 |
+
<h3>✨ Key Features</h3>
|
| 145 |
+
<ul>
|
| 146 |
+
<li>⚡ Real-time AI gesture recognition</li>
|
| 147 |
+
<li>🧠 Optimized for Russian Sign Language</li>
|
| 148 |
+
<li>🖥️ Lightweight and browser-based interface</li>
|
| 149 |
+
<li>🌍 Promoting accessibility and inclusive communication</li>
|
| 150 |
+
</ul>
|
| 151 |
+
</div>
|
| 152 |
+
""", unsafe_allow_html=True)
|
| 153 |
+
|
| 154 |
+
# --- How it works ---
|
| 155 |
+
st.markdown("""
|
| 156 |
+
<div class="section">
|
| 157 |
+
<h3>🛠 How it works</h3>
|
| 158 |
+
<ol>
|
| 159 |
+
<li>Camera captures hand gestures</li>
|
| 160 |
+
<li>Frame is processed via ONNX deep learning model</li>
|
| 161 |
+
<li>Text prediction appears instantly on screen</li>
|
| 162 |
+
</ol>
|
| 163 |
+
</div>
|
| 164 |
+
""", unsafe_allow_html=True)
|
| 165 |
+
|
| 166 |
+
# --- Upload Section ---
|
| 167 |
+
st.markdown("""
|
| 168 |
+
<div class="upload-section">
|
| 169 |
+
<h3>🎥 Sign Language Recognition Demo</h3>
|
| 170 |
+
<p>Upload a short video clip to detect sign gestures:</p>
|
| 171 |
+
</div>
|
| 172 |
+
""", unsafe_allow_html=True)
|
| 173 |
+
|
| 174 |
+
uploaded_file = st.file_uploader("Upload Video", type=["mp4", "avi", "mov", "gif"])
|
| 175 |
+
if uploaded_file:
|
| 176 |
+
st.video(uploaded_file)
|
| 177 |
+
else:
|
| 178 |
st.warning("Please upload a video file for prediction.")
|
| 179 |
|
| 180 |
+
# --- Contact block ---
|
| 181 |
+
st.markdown("""
|
| 182 |
+
<div class="contact-block">
|
| 183 |
+
<h3>📬 Let's collaborate!</h3>
|
| 184 |
+
<p>For demos, partnerships, or research opportunities:</p>
|
| 185 |
+
<p>Email: <a href="mailto:your@email.com">your@email.com</a></p>
|
| 186 |
+
</div>
|
| 187 |
+
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|