CoolFace
Apppublic

Nesakan/sastra-captcha

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
App README

SASTRA CAPTCHA Proxy Service

A lightweight Express.js service that fetches CAPTCHA images from the SASTRA webstream portal using Puppeteer.

Endpoints

EndpointMethodDescription
/GETHealth check (returns JSON status)
/healthGETHealth check (returns JSON status)
/captchaGETFetches CAPTCHA image (returns PNG)

Response Headers

The /captcha endpoint returns:

  • Content-Type: image/png
  • x-session-id: The JSESSIONID cookie needed for subsequent login requests

🚀 EXACT DEPLOYMENT STEPS

Follow these steps exactly to deploy to Hugging Face Spaces:

Step 1: Create a Hugging Face Account (if you don't have one)

  1. 1.Go to huggingface.co
  2. 2.Click Sign Up in the top right
  3. 3.Create your account and verify your email

Step 2: Create a New Space

  1. 1.Go to huggingface.co/new-space
  2. 2.Fill in the form:
  3. 3.Owner: Select your username
  4. 4.Space name: sastra-captcha (or any name you prefer)
  5. 5.License: MIT (or your preference)
  6. 6.SDK: Select Docker ⚠️ IMPORTANT!
  7. 7.Hardware: Select CPU basic (free tier: 2 vCPU, 16GB RAM)
  8. 8.Visibility: Public or Private (your choice)
  9. 9.Click Create Space

Step 3: Clone the Space Repository

After creating the space, you'll see instructions. Run these commands in your terminal:

bash
# Navigate to your project folder
cd d:\Projects\SastraWeb\hf-captcha

# Initialize git if not already
git init

# Add Hugging Face remote (replace Nesakan with your HF username)
git remote add origin https://huggingface.co/spaces/Nesakan/sastra-captcha

# OR if you already have a remote, set it:
git remote set-url origin https://huggingface.co/spaces/Nesakan/sastra-captcha

Step 4: Push Your Code

bash
# Stage all files
git add .

# Commit
git commit -m "Initial deployment"

# Push to Hugging Face (you'll be prompted for your HF credentials)
git push -u origin main
Note: If prompted for credentials, use: - Username: Your Hugging Face username - Password: Your Hugging Face Access Token (create one at Settings > Access Tokens)

Step 5: Wait for Build

  1. 1.Go to your Space page: https://huggingface.co/spaces/Nesakan/sastra-captcha
  2. 2.Click on the "Logs" tab to watch the build progress
  3. 3.Wait for the container to build and start (usually 2-5 minutes)
  4. 4.The status will change from "Building" to "Running"

Step 6: Test Your Service

Once running, your service will be available at:

https://Nesakan-sastra-captcha.hf.space

Test the endpoints:

  1. 1.Health Check: https://Nesakan-sastra-captcha.hf.space/
  2. 2.CAPTCHA: https://Nesakan-sastra-captcha.hf.space/captcha

Step 7: Update Your Frontend

Update your SASTRAWeb frontend to use the new URL. Find wherever your frontend calls the captcha API and change:

Old (Railway):

javascript
const response = await fetch('https://your-railway-url.railway.app/captcha');

New (Hugging Face):

javascript
const response = await fetch('https://Nesakan-sastra-captcha.hf.space/captcha');

Troubleshooting

Build Fails

  • Check the Logs tab for error messages
  • Ensure all files are committed and pushed

CAPTCHA Returns 503

  • The SASTRA portal might be temporarily unavailable
  • Check the Logs for detailed error messages

Slow Cold Start

  • First request after inactivity may take 10-30 seconds (this is normal for free tier)
  • Subsequent requests will be much faster

Local Testing (Optional)

If you have Docker installed locally, you can test before deploying:

bash
cd d:\Projects\SastraWeb\hf-captcha
docker build -t sastra-captcha .
docker run -p 7860:7860 sastra-captcha

Then open http://localhost:7860/captcha in your browser.