Spaces:
Sleeping
Sleeping
# Hugging Face Spaces Deployment Script | |
# This script helps set up your FastAPI application for Hugging Face Spaces | |
echo "π Setting up CSS Essay Grader API for Hugging Face Spaces..." | |
# Check if we're in the right directory | |
if [ ! -f "app.py" ]; then | |
echo "β Error: app.py not found. Please run this script from the project root directory." | |
exit 1 | |
fi | |
# Create necessary files for Hugging Face Spaces | |
echo "π Creating Hugging Face Spaces configuration files..." | |
# Copy the HF-specific app file | |
if [ -f "app_hf.py" ]; then | |
cp app_hf.py app.py | |
echo "β Copied app_hf.py to app.py" | |
else | |
echo "β οΈ Warning: app_hf.py not found. Using existing app.py" | |
fi | |
# Copy the HF-specific requirements file | |
if [ -f "requirements_hf.txt" ]; then | |
cp requirements_hf.txt requirements.txt | |
echo "β Copied requirements_hf.txt to requirements.txt" | |
else | |
echo "β οΈ Warning: requirements_hf.txt not found. Using existing requirements.txt" | |
fi | |
# Copy the HF-specific Dockerfile | |
if [ -f "Dockerfile.hf" ]; then | |
cp Dockerfile.hf Dockerfile | |
echo "β Copied Dockerfile.hf to Dockerfile" | |
else | |
echo "β οΈ Warning: Dockerfile.hf not found. Using existing Dockerfile" | |
fi | |
# Copy the HF-specific README | |
if [ -f "README_hf.md" ]; then | |
cp README_hf.md README.md | |
echo "β Copied README_hf.md to README.md" | |
else | |
echo "β οΈ Warning: README_hf.md not found. Using existing README.md" | |
fi | |
# Create .dockerignore if it doesn't exist | |
if [ ! -f ".dockerignore" ]; then | |
echo "π Creating .dockerignore file..." | |
cat > .dockerignore << EOF | |
# Git | |
.git | |
.gitignore | |
# Python | |
__pycache__ | |
*.pyc | |
*.pyo | |
*.pyd | |
.Python | |
env | |
pip-log.txt | |
pip-delete-this-directory.txt | |
.tox | |
.coverage | |
.coverage.* | |
.cache | |
nosetests.xml | |
coverage.xml | |
*.cover | |
*.log | |
.git | |
.mypy_cache | |
.pytest_cache | |
.hypothesis | |
# Virtual environments | |
venv/ | |
ENV/ | |
env/ | |
.venv/ | |
# IDE | |
.vscode/ | |
.idea/ | |
*.swp | |
*.swo | |
*~ | |
# OS | |
.DS_Store | |
.DS_Store? | |
._* | |
.Spotlight-V100 | |
.Trashes | |
ehthumbs.db | |
Thumbs.db | |
# Project specific | |
temp/ | |
output/ | |
*.png | |
*.jpg | |
*.jpeg | |
*.gif | |
*.bmp | |
*.tiff | |
*.docx | |
*.txt | |
*.log | |
# Development files | |
test_*.py | |
*_test.py | |
quick-fix.sh | |
optimize-deployment.py | |
deployment-guide.md | |
API_FORMAT_DOCUMENTATION.md | |
EOF | |
echo "β Created .dockerignore file" | |
fi | |
# Create necessary directories | |
echo "π Creating necessary directories..." | |
mkdir -p temp output | |
echo "β Created temp and output directories" | |
# Check for required files | |
echo "π Checking for required files..." | |
required_files=("app.py" "requirements.txt" "Dockerfile" "README.md" "OCR.py" "Feedback.py" "PDFFeedbackGenerator.py" "OCRAccuracyAnalyzer.py") | |
for file in "${required_files[@]}"; do | |
if [ -f "$file" ]; then | |
echo "β $file found" | |
else | |
echo "β $file missing" | |
fi | |
done | |
# Check for environment variables | |
echo "π§ Environment Variables Setup:" | |
echo " Make sure to set the following environment variables in your Hugging Face Space:" | |
echo " - OPENAI_API_KEY: Your OpenAI API key" | |
echo " - GOOGLE_CLOUD_CREDENTIALS: Your Google Cloud Vision credentials (JSON)" | |
# Display next steps | |
echo "" | |
echo "π Setup complete! Next steps:" | |
echo "" | |
echo "1. Create a new Hugging Face Space:" | |
echo " - Go to https://huggingface.co/spaces" | |
echo " - Click 'Create new Space'" | |
echo " - Choose 'Docker' as SDK" | |
echo " - Set Space name (e.g., 'css-essay-grader')" | |
echo "" | |
echo "2. Clone the Space repository:" | |
echo " git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME" | |
echo "" | |
echo "3. Copy your files to the Space repository:" | |
echo " cp -r * /path/to/your/space/repo/" | |
echo "" | |
echo "4. Set environment variables in the Space settings:" | |
echo " - OPENAI_API_KEY" | |
echo " - GOOGLE_CLOUD_CREDENTIALS" | |
echo "" | |
echo "5. Commit and push:" | |
echo " cd /path/to/your/space/repo/" | |
echo " git add ." | |
echo " git commit -m 'Initial deployment'" | |
echo " git push" | |
echo "" | |
echo "6. Wait for deployment (usually 5-10 minutes)" | |
echo "" | |
echo "7. Access your API:" | |
echo " https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space" | |
echo " https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/docs" | |
echo "" | |
echo "π Your CSS Essay Grader API is ready for Hugging Face Spaces deployment!" |