Spaces:
Sleeping
Sleeping
Said Lfagrouche
commited on
Commit
·
27a24b2
1
Parent(s):
542933f
Add new files
Browse files- api_mental_health.py +10 -4
- run_api.sh +21 -0
- setup_hf_deployment.sh +0 -60
api_mental_health.py
CHANGED
@@ -37,10 +37,16 @@ logger = logging.getLogger(__name__)
|
|
37 |
# Load environment variables
|
38 |
load_dotenv()
|
39 |
|
40 |
-
#
|
41 |
-
|
42 |
-
|
43 |
-
nltk.
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
# Initialize FastAPI app
|
46 |
app = FastAPI(title="Mental Health Counselor API")
|
|
|
37 |
# Load environment variables
|
38 |
load_dotenv()
|
39 |
|
40 |
+
# Set NLTK data path to a directory where we have write permissions
|
41 |
+
nltk_data_path = os.path.join(os.path.dirname(__file__), "nltk_data")
|
42 |
+
os.makedirs(nltk_data_path, exist_ok=True)
|
43 |
+
nltk.data.path.append(nltk_data_path)
|
44 |
+
|
45 |
+
# Download required NLTK data to our custom directory
|
46 |
+
logger.info(f"Downloading NLTK data to {nltk_data_path}")
|
47 |
+
nltk.download('punkt', download_dir=nltk_data_path)
|
48 |
+
nltk.download('wordnet', download_dir=nltk_data_path)
|
49 |
+
nltk.download('stopwords', download_dir=nltk_data_path)
|
50 |
|
51 |
# Initialize FastAPI app
|
52 |
app = FastAPI(title="Mental Health Counselor API")
|
run_api.sh
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# This script handles startup for the API on Hugging Face Spaces
|
4 |
+
echo "===== Application Startup at $(date -u '+%Y-%m-%d %H:%M:%S') ====="
|
5 |
+
|
6 |
+
# Make sure our custom directories are properly readable/writable
|
7 |
+
echo "Setting up directories with proper permissions..."
|
8 |
+
mkdir -p data/users data/sessions data/conversations data/feedback
|
9 |
+
mkdir -p mental_health_model_artifacts/chroma_db
|
10 |
+
mkdir -p nltk_data
|
11 |
+
chmod -R 777 data nltk_data mental_health_model_artifacts
|
12 |
+
|
13 |
+
# Create .env file if it doesn't exist
|
14 |
+
if [ ! -f .env ]; then
|
15 |
+
echo "Creating .env file from .env.example..."
|
16 |
+
cp .env.example .env
|
17 |
+
fi
|
18 |
+
|
19 |
+
# Start the API with uvicorn
|
20 |
+
echo "Starting API server..."
|
21 |
+
exec uvicorn app:app --host 0.0.0.0 --port 7860
|
setup_hf_deployment.sh
DELETED
@@ -1,60 +0,0 @@
|
|
1 |
-
#!/bin/bash
|
2 |
-
set -e
|
3 |
-
|
4 |
-
echo "Setting up deployment to Hugging Face Spaces..."
|
5 |
-
|
6 |
-
# Check if git is installed
|
7 |
-
if ! command -v git &> /dev/null; then
|
8 |
-
echo "Error: git is not installed. Please install git first."
|
9 |
-
exit 1
|
10 |
-
fi
|
11 |
-
|
12 |
-
# Check if git-lfs is installed
|
13 |
-
if ! command -v git-lfs &> /dev/null; then
|
14 |
-
echo "Error: git-lfs is not installed. Please install git-lfs first."
|
15 |
-
echo "You can install it with: brew install git-lfs (Mac) or sudo apt-get install git-lfs (Linux)"
|
16 |
-
exit 1
|
17 |
-
fi
|
18 |
-
|
19 |
-
# Initialize Git LFS
|
20 |
-
echo "Initializing Git LFS..."
|
21 |
-
git lfs install
|
22 |
-
|
23 |
-
# Create a new orphaned branch
|
24 |
-
echo "Creating new orphaned branch 'hf-deployment'..."
|
25 |
-
git checkout --orphan hf-deployment
|
26 |
-
|
27 |
-
# Remove all files from staging
|
28 |
-
echo "Clearing staging area..."
|
29 |
-
git rm -rf --cached .
|
30 |
-
|
31 |
-
# Keep the .gitattributes and .gitignore files
|
32 |
-
echo "Adding .gitattributes and .gitignore..."
|
33 |
-
git add .gitattributes .gitignore
|
34 |
-
|
35 |
-
# Make sure the LFS tracking is set up correctly
|
36 |
-
echo "Setting up LFS tracking for large files..."
|
37 |
-
git lfs track "*.sqlite3"
|
38 |
-
git lfs track "*.pkl"
|
39 |
-
git lfs track "*.bin"
|
40 |
-
git lfs track "mental_health_model_artifacts/chroma_db/chroma.sqlite3"
|
41 |
-
git lfs track "mental_health_model_artifacts/chroma_db/**/*.bin"
|
42 |
-
git lfs track "mental_health_model_artifacts/**/*.pkl"
|
43 |
-
|
44 |
-
# Add all files
|
45 |
-
echo "Adding all files to staging..."
|
46 |
-
git add .
|
47 |
-
|
48 |
-
# Commit the changes
|
49 |
-
echo "Committing changes..."
|
50 |
-
git commit -m "Initial deployment with Git LFS enabled"
|
51 |
-
|
52 |
-
echo "======================================================"
|
53 |
-
echo "Setup complete! To push to Hugging Face Spaces, run:"
|
54 |
-
echo "git push -u origin hf-deployment --force"
|
55 |
-
echo ""
|
56 |
-
echo "If this is successful and you want to make this the main branch:"
|
57 |
-
echo "1. Go to Hugging Face Spaces and set 'hf-deployment' as the default branch"
|
58 |
-
echo "2. Rename the branch locally: git branch -m hf-deployment main"
|
59 |
-
echo "3. Push to origin: git push -u origin main"
|
60 |
-
echo "======================================================"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|