Spaces:
Sleeping
Sleeping
Download train_platform.py from KrishDev15/Sign_intrepreter: direct link, hf CLI and curl.
- Browser
- Download file 2.52 kB
-
https://huggingface.co/spaces/KrishDev15/Sign_intrepreter/resolve/main/train_platform.py
- Command line
-
hf download hf://spaces/KrishDev15/Sign_intrepreter/train_platform.py
-
curl -L -o train_platform.py https://huggingface.co/spaces/KrishDev15/Sign_intrepreter/resolve/main/train_platform.py
2.52 kB
| import streamlit as st | |
| import cv2 | |
| import numpy as np | |
| import os | |
| import tensorflow as tf | |
| from tensorflow.keras.models import Sequential | |
| from tensorflow.keras.layers import LSTM, Dense, Dropout | |
| from tensorflow.keras.callbacks import ModelCheckpoint, TensorBoard | |
| import mediapipe as mp | |
| from utils.data_utils import process_video, extract_landmarks | |
| from utils.model_utils import create_model, convert_to_tflite | |
| def main(): | |
| st.title("Sign Language Model Training Platform") | |
| # Sidebar for training configuration | |
| st.sidebar.header("Training Configuration") | |
| # Model parameters | |
| num_classes = st.sidebar.number_input("Number of Sign Classes", min_value=2, value=10) | |
| epochs = st.sidebar.number_input("Training Epochs", min_value=1, value=50) | |
| batch_size = st.sidebar.number_input("Batch Size", min_value=1, value=32) | |
| # Dataset upload | |
| st.header("Dataset Upload") | |
| dataset_path = st.file_uploader("Upload Dataset (ZIP file containing video folders)", type=['zip']) | |
| if dataset_path: | |
| # Create progress bar | |
| progress_bar = st.progress(0) | |
| status_text = st.empty() | |
| # Extract dataset | |
| status_text.text("Extracting dataset...") | |
| # TODO: Add dataset extraction logic | |
| # Process videos and extract landmarks | |
| status_text.text("Processing videos and extracting landmarks...") | |
| X_train, y_train = [], [] | |
| # TODO: Add video processing logic using MediaPipe | |
| # Create and train model | |
| if st.button("Start Training"): | |
| status_text.text("Creating model...") | |
| model = create_model(num_classes) | |
| status_text.text("Training model...") | |
| history = model.fit( | |
| X_train, y_train, | |
| epochs=epochs, | |
| batch_size=batch_size, | |
| validation_split=0.2, | |
| callbacks=[ | |
| ModelCheckpoint('models/best_model.h5', save_best_only=True), | |
| TensorBoard(log_dir='logs') | |
| ] | |
| ) | |
| # Convert to TFLite | |
| status_text.text("Converting model to TFLite...") | |
| convert_to_tflite(model, 'models/model.tflite') | |
| st.success("Training completed! Model saved as 'model.tflite'") | |
| # Display training metrics | |
| st.header("Training Results") | |
| st.line_chart(history.history) | |
| if __name__ == "__main__": | |
| main() | |