Abs6187 commited on
Commit
76ef804
Β·
verified Β·
1 Parent(s): fd46721

Upload 13 files

Browse files
Files changed (5) hide show
  1. .dockerignore +31 -0
  2. .gitignore +7 -2
  3. Dockerfile +39 -32
  4. app.py +149 -79
  5. requirements.txt +15 -16
.dockerignore ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Git and version control
2
+ .git
3
+ .gitignore
4
+
5
+ # Python cache
6
+ __pycache__/
7
+ *.pyc
8
+ *.pyo
9
+ *.pyd
10
+ .Python
11
+ *.so
12
+
13
+ # Jupyter Notebook
14
+ .ipynb_checkpoints
15
+
16
+ # IDE
17
+ .vscode/
18
+ .idea/
19
+ *.swp
20
+ *.swo
21
+
22
+ # OS
23
+ .DS_Store
24
+ Thumbs.db
25
+
26
+ # Documentation (if any)
27
+ *.md
28
+ !README.md
29
+
30
+ # Logs
31
+ *.log
.gitignore CHANGED
@@ -82,5 +82,10 @@ checkpoints/
82
  logs/
83
  *.log
84
 
85
- # Original project reference (keep for development)
86
- original_project/
 
 
 
 
 
 
82
  logs/
83
  *.log
84
 
85
+ # Original project reference (exclude from deployment)
86
+ original_project/
87
+
88
+ # HuggingFace Spaces specific
89
+ .space/
90
+ *.log
91
+ flagged/
Dockerfile CHANGED
@@ -1,32 +1,39 @@
1
- FROM python:3.13.5-slim
2
-
3
- WORKDIR /app
4
-
5
- # Install OS-level dependencies if your app needs them (e.g. building wheels, git, curl)
6
- RUN apt-get update && apt-get install -y \
7
- build-essential \
8
- curl \
9
- git \
10
- && rm -rf /var/lib/apt/lists/*
11
-
12
- # Copy dependency spec and source code
13
- COPY requirements.txt ./
14
- COPY src/ ./src/
15
-
16
- # Install Python dependencies
17
- RUN pip3 install --no-cache-dir -r requirements.txt
18
-
19
- # (Optional) Set environment variables useful in HF Spaces / container environment
20
- # Avoid Streamlit trying to write to root directories it might not have permission to.
21
- ENV STREAMLIT_HOME=/tmp/.streamlit
22
- ENV STREAMLIT_BROWSER_GATHER_USAGE_STATS=false
23
-
24
- # Expose the port used by Streamlit in HF (8501)
25
- EXPOSE 8501
26
-
27
- # Healthcheck: test whether Streamlit's health endpoint is alive
28
- # But note: there are known issues with Streamlit health endpoint in some environments. :contentReference[oaicite:2]{index=2}
29
- HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
30
-
31
- # Launch Streamlit app; bind to 0.0.0.0 so external connections work
32
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
 
 
 
 
 
 
 
 
1
+ FROM python:3.13.5-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Install OS-level dependencies including ffmpeg and OpenCV requirements
6
+ RUN apt-get update && apt-get install -y \
7
+ build-essential \
8
+ curl \
9
+ git \
10
+ ffmpeg \
11
+ libsm6 \
12
+ libxext6 \
13
+ libfontconfig1 \
14
+ libxrender1 \
15
+ libgl1-mesa-glx \
16
+ libglib2.0-0 \
17
+ && rm -rf /var/lib/apt/lists/*
18
+
19
+ # Copy dependency spec and source code
20
+ COPY requirements.txt ./
21
+ COPY . ./
22
+
23
+ # Install Python dependencies
24
+ RUN pip3 install --no-cache-dir -r requirements.txt
25
+
26
+ # Set environment variables for Streamlit and Keras
27
+ ENV STREAMLIT_HOME=/tmp/.streamlit
28
+ ENV STREAMLIT_BROWSER_GATHER_USAGE_STATS=false
29
+ ENV KERAS_BACKEND=torch
30
+ ENV OPENCV_LOG_LEVEL=ERROR
31
+
32
+ # Expose the port used by Streamlit
33
+ EXPOSE 8501
34
+
35
+ # Healthcheck: test whether Streamlit's health endpoint is alive
36
+ HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
37
+
38
+ # Launch Streamlit app; bind to 0.0.0.0 so external connections work
39
+ ENTRYPOINT ["streamlit", "run", "app.py", "--server.port=8501", "--server.address=0.0.0.0"]
app.py CHANGED
@@ -12,49 +12,87 @@ Institution: Shri Ram Group of Institutions
12
  """
13
 
14
  import streamlit as st
15
- st.write("πŸš€ TechMatrix Solvers ISL Translator Loading...")
16
 
17
- import os
18
- os.environ["KERAS_BACKEND"] = "torch"
19
- import keras
20
-
21
- import cv2
22
- import numpy as np
23
- import tempfile
24
- import time
25
- from PIL import Image
26
- from keras.models import Sequential
27
- import pickle
28
- from keras.layers import LSTM, Dense, Bidirectional, Dropout, Input, BatchNormalization
29
- from pose_models import create_bodypose_model, create_handpose_model
30
- from expression_mapping import expression_mapping
31
- from isl_processor import ISLTranslationModel
32
- import pandas as pd
33
- import ffmpeg
34
- import subprocess
35
- from typing import NamedTuple
36
- import json
37
- import pose_utils as utils
38
- from huggingface_hub import hf_hub_download
39
- import shutil, platform
40
- import uuid
41
-
42
- # System information display
43
- st.write("πŸ”§ **System Information:**")
44
- st.write(f"Python Version: {platform.python_version()}")
45
- st.write(f"FFmpeg: {shutil.which('ffmpeg')}, FFprobe: {shutil.which('ffprobe')}")
46
 
47
- try:
48
- import cv2
49
- st.write(f"OpenCV Version: {cv2.__version__}")
50
- except Exception as e:
51
- st.error(f"OpenCV import failed: {e}")
52
 
 
53
  try:
54
- import torch
55
- st.write(f"PyTorch: {torch.__version__}, Keras: {keras.__version__}")
56
- except Exception as e:
57
- st.error(f"PyTorch/Keras import failed: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
 
60
  class VideoProbeResult(NamedTuple):
@@ -159,38 +197,46 @@ def load_translation_model():
159
  Load and configure the LSTM translation model
160
 
161
  Returns:
162
- Configured Keras Sequential model for ISL translation
163
  """
164
- model = Sequential()
165
- model.add(Input(shape=((20, 156))))
166
- model.add(keras.layers.Masking(mask_value=0.))
167
- model.add(BatchNormalization())
168
- model.add(Bidirectional(LSTM(32, recurrent_dropout=0.2, return_sequences=True)))
169
-
170
- model.add(Dropout(0.2))
171
- model.add(Bidirectional(LSTM(32, recurrent_dropout=0.2)))
172
-
173
- model.add(keras.layers.Activation('elu'))
174
- model.add(Dense(32, use_bias=False, kernel_initializer='he_normal'))
175
-
176
- model.add(BatchNormalization())
177
- model.add(Dropout(0.2))
178
- model.add(keras.layers.Activation('elu'))
179
- model.add(Dense(32, kernel_initializer='he_normal', use_bias=False))
180
-
181
- model.add(BatchNormalization())
182
- model.add(keras.layers.Activation('elu'))
183
- model.add(Dropout(0.2))
184
- model.add(Dense(len(list(expression_mapping.keys())), activation='softmax'))
185
-
186
- # Download pre-trained model weights
187
- model_file = hf_hub_download(
188
- repo_id="sunilsarolkar/isl-translation-model",
189
- filename="isl_model_final.keras"
190
- )
191
- model.load_weights(model_file)
192
-
193
- return model
 
 
 
 
 
 
 
 
194
 
195
 
196
  # Load test data
@@ -215,8 +261,7 @@ def load_test_data():
215
  return testing_df, test_files_df
216
 
217
 
218
- # Load test data
219
- testing_df, test_files_df = load_test_data()
220
 
221
 
222
  class VideoWriter:
@@ -292,12 +337,7 @@ def resize_image(image, width=None, height=None, interpolation=cv2.INTER_AREA):
292
  return resized
293
 
294
 
295
- # Configure Streamlit page
296
- st.set_page_config(
297
- page_title="ISL Translation - TechMatrix Solvers",
298
- page_icon="🀟",
299
- layout="wide"
300
- )
301
 
302
  st.title('🀟 ISL Sign Language Translation - TechMatrix Solvers Initiative')
303
 
@@ -490,6 +530,27 @@ if app_mode == 'About Project':
490
  """
491
  )
492
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
493
  # Team contact information
494
  st.markdown(
495
  """
@@ -498,7 +559,7 @@ if app_mode == 'About Project':
498
  **TechMatrix Solvers Team:**
499
 
500
  | Name | Role | Email | Phone |
501
- |------|------|-------|--------|
502
  | **Abhay Gupta** | Team Lead | contact2abhaygupta6187@gmail.com | 8115814535 |
503
  | **Kripanshu Gupta** | Backend Developer | guptakripanshu83@gmail.com | 7067058400 |
504
  | **Dipanshu Patel** | UI/UX Designer | dipanshupatel43@gmail.com | 9294526404 |
@@ -521,6 +582,15 @@ elif app_mode == 'Test Video Translation':
521
  # Video selection interface
522
  st.markdown("## πŸŽ₯ Test Video Translation")
523
 
 
 
 
 
 
 
 
 
 
524
  category = st.sidebar.selectbox(
525
  'Choose Category',
526
  np.sort(test_files_df['Category'].unique(), axis=-1, kind='mergesort')
 
12
  """
13
 
14
  import streamlit as st
 
15
 
16
+ # Configure Streamlit page first
17
+ st.set_page_config(
18
+ page_title="ISL Translation - TechMatrix Solvers",
19
+ page_icon="🀟",
20
+ layout="wide",
21
+ initial_sidebar_state="expanded"
22
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
+ # Show loading message
25
+ st.write("πŸš€ TechMatrix Solvers ISL Translator Loading...")
 
 
 
26
 
27
+ # Import dependencies with error handling
28
  try:
29
+ import os
30
+ os.environ["KERAS_BACKEND"] = "torch"
31
+
32
+ # Core imports
33
+ import numpy as np
34
+ import pandas as pd
35
+ import tempfile
36
+ import time
37
+ from PIL import Image
38
+ import subprocess
39
+ from typing import NamedTuple
40
+ import json
41
+ import shutil
42
+ import platform
43
+ import uuid
44
+
45
+ # Try OpenCV import
46
+ try:
47
+ import cv2
48
+ except Exception as cv_error:
49
+ st.warning(f"OpenCV import issue: {cv_error}")
50
+ cv2 = None
51
+
52
+ # Try ML library imports
53
+ try:
54
+ import keras
55
+ from keras.models import Sequential
56
+ from keras.layers import LSTM, Dense, Bidirectional, Dropout, Input, BatchNormalization
57
+ except Exception as keras_error:
58
+ st.warning(f"Keras import issue: {keras_error}")
59
+ keras = None
60
+
61
+ # Try video processing
62
+ try:
63
+ import ffmpeg
64
+ except Exception as ffmpeg_error:
65
+ st.warning(f"FFmpeg import issue: {ffmpeg_error}")
66
+ ffmpeg = None
67
+
68
+ # Try HuggingFace Hub
69
+ try:
70
+ from huggingface_hub import hf_hub_download
71
+ except Exception as hf_error:
72
+ st.warning(f"HuggingFace Hub import issue: {hf_error}")
73
+ hf_hub_download = None
74
+
75
+ # Try custom modules with fallback
76
+ try:
77
+ from pose_models import create_bodypose_model, create_handpose_model
78
+ from expression_mapping import expression_mapping
79
+ from isl_processor import ISLTranslationModel
80
+ import pose_utils as utils
81
+ except Exception as custom_error:
82
+ st.warning(f"Custom modules import issue: {custom_error}")
83
+ # Fallback expression mapping
84
+ expression_mapping = {
85
+ 'hello': 0, 'thank_you': 1, 'please': 2, 'sorry': 3, 'help': 4,
86
+ 'good': 5, 'bad': 6, 'yes': 7, 'no': 8, 'water': 9,
87
+ 'food': 10, 'home': 11, 'work': 12, 'school': 13, 'family': 14
88
+ }
89
+
90
+ st.success("βœ… Core dependencies loaded successfully!")
91
+ except ImportError as e:
92
+ st.error(f"❌ Critical import error: {e}")
93
+ st.error("Running in fallback mode with limited functionality.")
94
+
95
+ # System information will be shown in About section
96
 
97
 
98
  class VideoProbeResult(NamedTuple):
 
197
  Load and configure the LSTM translation model
198
 
199
  Returns:
200
+ Configured Keras Sequential model for ISL translation or None if failed
201
  """
202
+ try:
203
+ if keras is None or hf_hub_download is None:
204
+ st.warning("Keras or HuggingFace Hub not available. Model loading skipped.")
205
+ return None
206
+
207
+ model = Sequential()
208
+ model.add(Input(shape=((20, 156))))
209
+ model.add(keras.layers.Masking(mask_value=0.))
210
+ model.add(BatchNormalization())
211
+ model.add(Bidirectional(LSTM(32, recurrent_dropout=0.2, return_sequences=True)))
212
+
213
+ model.add(Dropout(0.2))
214
+ model.add(Bidirectional(LSTM(32, recurrent_dropout=0.2)))
215
+
216
+ model.add(keras.layers.Activation('elu'))
217
+ model.add(Dense(32, use_bias=False, kernel_initializer='he_normal'))
218
+
219
+ model.add(BatchNormalization())
220
+ model.add(Dropout(0.2))
221
+ model.add(keras.layers.Activation('elu'))
222
+ model.add(Dense(32, kernel_initializer='he_normal', use_bias=False))
223
+
224
+ model.add(BatchNormalization())
225
+ model.add(keras.layers.Activation('elu'))
226
+ model.add(Dropout(0.2))
227
+ model.add(Dense(len(list(expression_mapping.keys())), activation='softmax'))
228
+
229
+ # Download pre-trained model weights
230
+ model_file = hf_hub_download(
231
+ repo_id="sunilsarolkar/isl-translation-model",
232
+ filename="isl_model_final.keras"
233
+ )
234
+ model.load_weights(model_file)
235
+
236
+ return model
237
+ except Exception as e:
238
+ st.error(f"Failed to load translation model: {e}")
239
+ return None
240
 
241
 
242
  # Load test data
 
261
  return testing_df, test_files_df
262
 
263
 
264
+ # Test data will be loaded when needed
 
265
 
266
 
267
  class VideoWriter:
 
337
  return resized
338
 
339
 
340
+ # Page configuration already set at the top
 
 
 
 
 
341
 
342
  st.title('🀟 ISL Sign Language Translation - TechMatrix Solvers Initiative')
343
 
 
530
  """
531
  )
532
 
533
+ # System Information
534
+ st.markdown("### πŸ”§ System Information")
535
+ col1, col2 = st.columns(2)
536
+
537
+ with col1:
538
+ st.write(f"**Python Version:** {platform.python_version()}")
539
+ st.write(f"**FFmpeg:** {shutil.which('ffmpeg') or 'Not found'}")
540
+ st.write(f"**FFprobe:** {shutil.which('ffprobe') or 'Not found'}")
541
+
542
+ with col2:
543
+ try:
544
+ st.write(f"**OpenCV Version:** {cv2.__version__}")
545
+ except:
546
+ st.write("**OpenCV:** Not available")
547
+ try:
548
+ import torch
549
+ st.write(f"**PyTorch:** {torch.__version__}")
550
+ st.write(f"**Keras:** {keras.__version__}")
551
+ except:
552
+ st.write("**PyTorch/Keras:** Not available")
553
+
554
  # Team contact information
555
  st.markdown(
556
  """
 
559
  **TechMatrix Solvers Team:**
560
 
561
  | Name | Role | Email | Phone |
562
+ |------|------|-------|---------|
563
  | **Abhay Gupta** | Team Lead | contact2abhaygupta6187@gmail.com | 8115814535 |
564
  | **Kripanshu Gupta** | Backend Developer | guptakripanshu83@gmail.com | 7067058400 |
565
  | **Dipanshu Patel** | UI/UX Designer | dipanshupatel43@gmail.com | 9294526404 |
 
582
  # Video selection interface
583
  st.markdown("## πŸŽ₯ Test Video Translation")
584
 
585
+ # Load test data dynamically
586
+ with st.spinner("Loading test data..."):
587
+ try:
588
+ testing_df, test_files_df = load_test_data()
589
+ st.success("βœ… Test data loaded successfully!")
590
+ except Exception as e:
591
+ st.error(f"❌ Failed to load test data: {e}")
592
+ st.stop()
593
+
594
  category = st.sidebar.selectbox(
595
  'Choose Category',
596
  np.sort(test_files_df['Category'].unique(), axis=-1, kind='mergesort')
requirements.txt CHANGED
@@ -1,16 +1,15 @@
1
- opencv-python-headless==4.7.1.72
2
- streamlit==1.28.1
3
- numpy==1.24.3
4
- Pillow==9.5.0
5
- matplotlib==3.5.3
6
- scipy==1.10.1
7
- scikit-image==0.20.0
8
- tqdm==4.65.0
9
- pandas==2.0.3
10
- torch==2.0.1
11
- torchvision==0.15.2
12
- av==10.0.0
13
- keras==2.13.1
14
- ffmpeg-python==0.2.0
15
- seaborn==0.12.2
16
- huggingface_hub==0.16.4
 
1
+ opencv-python-headless==4.8.1.78
2
+ streamlit==1.28.1
3
+ numpy==1.24.3
4
+ Pillow==9.5.0
5
+ matplotlib==3.5.3
6
+ scipy==1.10.1
7
+ scikit-image==0.20.0
8
+ tqdm==4.65.0
9
+ pandas==2.0.3
10
+ torch==2.0.1
11
+ torchvision==0.15.2
12
+ keras==2.13.1
13
+ ffmpeg-python==0.2.0
14
+ seaborn==0.12.2
15
+ huggingface_hub==0.16.4