--- title: DailyRA emoji: πŸš€ colorFrom: gray colorTo: yellow sdk: docker pinned: false --- # ζ—₯欑RA (Daily Risk Assessment) A Streamlit application for daily risk assessment in construction and industrial settings, with automatic safety rule generation. ## πŸš€ Features - **Daily Risk Assessment Form**: Input work details, hazards, and mitigation measures - **Automatic Rule Generation**: AI-powered safety rule extraction based on object relationships - **Database Storage**: Persistent storage using Supabase PostgreSQL - **Modern Dependency Management**: Uses `uv` for fast package management ## πŸ“¦ Technology Stack - **Frontend**: Streamlit - **Database**: Supabase (PostgreSQL) - **NLP**: SudachiPy (Japanese tokenization) - **ML**: Sentence Transformers - **Package Manager**: uv ## πŸƒ Quick Start See [DEPLOYMENT.md](./DEPLOYMENT.md) for detailed setup instructions. ### Local Development ```bash # Install uv curl -LsSf https://astral.sh/uv/install.sh | sh # Install package in editable mode (installs dependencies + package) uv pip install -e . # Set up environment variables cp env.example .env # Edit .env with your Supabase credentials # Run the app streamlit run src/daily_ra/app.py ``` ### Docker ```bash docker build -t daily-ra . docker run -p 7860:7860 --env-file .env daily-ra ``` ## πŸ“¦ Using UV ### Common Commands ```bash # Install dependencies from pyproject.toml uv pip install -e . # Add a new package uv add requests # Add with version constraint uv add "pandas>=2.0.0" # Remove a package uv remove package-name # Update all packages uv pip install --upgrade -e . ``` # Deployment Guide ## πŸ“¦ Setup Instructions ### 1️⃣ **Set Up Supabase Database** 1. Go to your Supabase project dashboard 2. Open the SQL Editor 3. Copy and paste the contents of `schema.sql` 4. Run the SQL to create the tables ### 2️⃣ **Local Development** 1. Install uv (if not already installed): ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` 2. Create a `.env` file in the project root (use `env.example` as template): ```bash cp env.example .env ``` 3. Fill in your Supabase connection details in `.env`: ``` HOST=aws-1-ap-northeast-1.pooler.supabase.com PORT=5432 DATABASE=postgres USERNAME=postgres.vvkubjwatpdqnkmgmntf PASSWORD=your-actual-password POOL_NAME=vvkubjwatpdqnkmgmntf ``` 4. Install package in editable mode: ```bash uv pip install -e . ``` 5. Run the app locally: ```bash streamlit run src/daily_ra/app.py ``` ### 3️⃣ **Deploy to Hugging Face Spaces** 1. Push your code to the Hugging Face Space repository 2. Go to your Space Settings β†’ **Repository secrets** 3. Add the following secrets (get these from your Supabase project settings): - `HOST` = `aws-1-ap-northeast-1.pooler.supabase.com` (your pooler host) - `PORT` = `5432` - `DATABASE` = `postgres` - `USERNAME` = `postgres.vvkubjwatpdqnkmgmntf` (format: postgres.YOUR_PROJECT_REF) - `PASSWORD` = `your-actual-password` 4. The app will automatically rebuild and deploy --- ## πŸ” Troubleshooting ### Connection Issues - Verify your Supabase password is correct - Check that your IP is not blocked in Supabase settings - Ensure connection pooling is enabled in Supabase ### Table Errors - Make sure you've run the `schema.sql` in Supabase SQL Editor - Verify the table names match exactly ### Environment Variables - On Hugging Face Spaces, use **Repository secrets** (not .env file) - Variable names must match exactly: `HOST`, `PORT`, `DATABASE`, `USERNAME`, `PASSWORD`, `POOL_NAME` --- ## πŸ“Š Database Tables ### `daily_ra` Table Stores daily risk assessment entries with work details, hazards, and mitigation measures. ### `rule_base` Table Stores automatically generated safety rules based on object relationships and potential risks.