Moderator404 commited on
Commit
0764160
·
verified ·
1 Parent(s): 2883155

Create entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +45 -0
entrypoint.sh ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ echo "Starting TMC Chatbot on Hugging Face Spaces..."
5
+
6
+ # Disable telemetry
7
+ export ANONYMIZED_TELEMETRY=False
8
+ export CHROMA_TELEMETRY_ENABLED=false
9
+ export CHROMADB_TELEMETRY_DISABLED=true
10
+ export POSTHOG_DISABLED=true
11
+
12
+ # Create necessary directories
13
+ mkdir -p /app/data/transformers_cache
14
+ mkdir -p /app/data/huggingface_cache
15
+ mkdir -p /app/data/vector_db
16
+ mkdir -p /app/data/sentence_transformers_cache
17
+
18
+ # Set database path
19
+ export DATABASE_PATH=${DATABASE_PATH:-/app/data/tmc_customer_service.db}
20
+
21
+ # Initialize database if needed
22
+ if [ ! -f "$DATABASE_PATH" ]; then
23
+ echo "Database not found. Creating tables and default users..."
24
+ python -c "
25
+ from scripts.init_database import init_sample_data
26
+ init_sample_data()
27
+ print('Database initialized with default users.')
28
+ "
29
+ else
30
+ # Check if users exist
31
+ USER_COUNT=$(python -c "import sqlite3; conn = sqlite3.connect('$DATABASE_PATH'); cur = conn.cursor(); cur.execute('SELECT COUNT(*) FROM users'); print(cur.fetchone()[0]); conn.close()" 2>/dev/null || echo "0")
32
+ if [ "$USER_COUNT" = "0" ]; then
33
+ echo "Database exists but has no users. Adding default users..."
34
+ python -c "
35
+ from scripts.init_database import init_sample_data
36
+ init_sample_data()
37
+ print('Default users added.')
38
+ "
39
+ else
40
+ echo "Database already initialized with $USER_COUNT user(s)."
41
+ fi
42
+ fi
43
+
44
+ echo "Starting Flask application on port 7860..."
45
+ exec python app.py