Hugging Face Spaces Deployment Guide for TalimBot
Status: Ready to Deploy β
All necessary files have been created and committed. Follow the steps below to complete the deployment.
Files Created
- Dockerfile - Docker configuration for HF Spaces (port 7860)
- .dockerignore - Excludes unnecessary files from Docker build
- README_HF.md - Hugging Face Space description with metadata
Step 1: Get Your Hugging Face Access Token
- Go to: https://huggingface.co/settings/tokens
- Click "New token"
- Name it:
TalimBot Deploy - Type: Write (must have write permissions)
- Click "Generate a token"
- COPY THE TOKEN (you won't see it again!)
Step 2: Push to Hugging Face
The git remote is already configured. Now push your code:
git push huggingface main
When prompted:
- Username:
parinazAkef(your HF username) - Password: Paste your access token (not your actual password!)
Step 3: Configure Environment Secret
- Go to: https://huggingface.co/spaces/parinazAkef/talimbot
- Click the Settings tab (top of page)
- Scroll to "Variables and secrets"
- Click "New secret"
- Name:
OPENROUTER_API_KEY - Value: Your OpenRouter API key (starts with
sk-or-v1-) - Click "Save"
β You've already done this step!
Step 4: Wait for Build
After pushing, Hugging Face will:
- Show "Building" status (3-5 minutes)
- Pull Docker image, install dependencies
- Start your FastAPI app on port 7860
- Show "Running" status when ready
Step 5: Access Your Live App
Once status shows "Running" (green), your app will be available at:
Primary URL:
https://huggingface.co/spaces/parinazAkef/talimbot
Direct URL (no HF frame):
https://parinazakef-talimbot.hf.space
Step 6: Test the Application
Teacher Login
- Go to your HF Space URL
- Click on "Ω ΨΉΩΩ " (Teacher)
- Password:
teacher123 - You should see the teacher dashboard
Student Login
- Click on "Ψ―Ψ§ΩΨ΄ Ψ’Ω ΩΨ²" (Student)
- Enter national code:
0921111111(demo account) - You should see: ΩΎΨ±ΫΩΨ§Ψ² ΨΉΨ§Ϊ©Ω dashboard
Test Grouping
- Login as teacher
- Use "ΩΎΨ± Ϊ©Ψ±Ψ―Ω Ψ―Ψ§Ψ―ΩβΩΨ§Ϋ ΨͺΨ³Ψͺ" to generate 10 sample students
- Click "Ψ΄Ψ±ΩΨΉ Ϊ―Ψ±ΩΩβΨ¨ΩΨ―Ϋ"
- Enter course name (e.g., "Ψ±ΫΨ§ΨΆΫ")
- Wait 30-60 seconds for AI grouping
- Check results!
Troubleshooting
If Build Fails
Error: "Port 7860 not listening"
- Fixed! Our Dockerfile uses
--port 7860
Error: "OPENROUTER_API_KEY not found"
- Go to Space Settings β Add secret
OPENROUTER_API_KEY
Error: "File not found: main.py"
- Fixed! Dockerfile copies
backend/folder and sets working directory
If Push Fails
Error: "Authentication failed"
- Make sure you're using an access token, not your password
- Generate new token with Write permissions
Error: "Repository not found"
- Check space URL: https://huggingface.co/spaces/parinazAkef/talimbot
- Make sure space exists and is public
File Structure (Docker Container)
/app/
βββ requirements.txt
βββ backend/
β βββ main.py # FastAPI app (runs on port 7860)
β βββ grouping_logic.py # AI grouping algorithm
β βββ data/
β β βββ students.json.backup # Initial data template
β βββ static/
β βββ pages/ # HTML pages
β βββ assets/ # CSS, JS files
β βββ Icons/ # Images
βββ resources_references/ # Documentation
Environment Variables
The Space automatically provides:
OPENROUTER_API_KEY(from Secrets)PORT=7860(HF Spaces requirement)
Your FastAPI app reads OPENROUTER_API_KEY via:
api_key = os.getenv("OPENROUTER_API_KEY")
Next Steps After Deployment
- Update GitHub README - Add HF Space badge and link
- Share URL - Send to users/colleagues
- Monitor Usage - Check Logs tab in HF Space
- Add to Profile - Pin Space to your HF profile
Updating Your App
To push changes:
# Make your code changes
git add .
git commit -m "Your update description"
# Push to GitHub (optional)
git push fork main
# Push to Hugging Face (triggers rebuild)
git push huggingface main
HF will automatically rebuild and redeploy!
Comparison: Railway vs Hugging Face
| Feature | Railway | Hugging Face |
|---|---|---|
| Free Tier | 500 hours/month | Unlimited (24/7) |
| Sleep Mode | No | No |
| Cold Start | No | No |
| Iran Access | Sometimes blocked | More accessible |
| Custom Domain | Yes (paid) | Yes (subdomain free) |
| Secrets | Environment variables | Secrets (encrypted) |
| Logs | Real-time | Real-time |
| Auto-deploy | Git push | Git push |
Contact & Support
- Hugging Face Docs: https://huggingface.co/docs/hub/spaces-sdks-docker
- Your Space: https://huggingface.co/spaces/parinazAkef/talimbot
- OpenRouter Docs: https://openrouter.ai/docs
Summary
β Completed:
- Created Dockerfile (port 7860)
- Created .dockerignore
- Created README_HF.md
- Committed files to git
- Added HF remote
π Your Action Required:
- Get HF access token from https://huggingface.co/settings/tokens
- Run:
git push huggingface main - Enter username + token when prompted
- Wait for "Running" status
- Test at: https://parinazakef-talimbot.hf.space
Good luck! π