File size: 4,200 Bytes
459923e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash

# 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/
*.pdf
*.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!"