Docgenie-API / api /quick_test.sh
Ahadhassan-2003
deploy: update HF Space
5c36ec7
#!/bin/bash
# Quick test script - tests async API with Google Drive upload
# Usage: ./quick_test.sh YOUR_GOOGLE_ACCESS_TOKEN
set -e
GOOGLE_TOKEN=$1
BASE_URL=${2:-"http://localhost:8000"}
if [ -z "$GOOGLE_TOKEN" ]; then
echo "Usage: ./quick_test.sh YOUR_GOOGLE_ACCESS_TOKEN [BASE_URL]"
echo ""
echo "To get a Google token, run:"
echo " python test_get_google_token.py --client-id YOUR_ID --client-secret YOUR_SECRET"
echo ""
echo "Or see TESTING.md for detailed instructions"
exit 1
fi
echo "==========================================="
echo "Quick Test: Async API + Google Drive"
echo "==========================================="
echo "API: $BASE_URL"
echo "Token: ${GOOGLE_TOKEN:0:20}..."
echo ""
# Step 1: Health check
echo "1. Health Check..."
curl -s "$BASE_URL/health" | python -m json.tool
echo ""
# Step 2: Submit job
echo "2. Submitting Job..."
RESPONSE=$(curl -s -X POST "$BASE_URL/generate/async" \
-H "Content-Type: application/json" \
-d "{
\"user_id\": 1,
\"google_drive_token\": \"$GOOGLE_TOKEN\",
\"seed_images\": [\"https://ocr.space/Content/Images/receipt-ocr-original.webp\"],
\"prompt_params\": {
\"language\": \"English\",
\"doc_type\": \"receipts\",
\"num_solutions\": 1,
\"enable_handwriting\": false,
\"enable_visual_elements\": false,
\"output_detail\": \"minimal\"
}
}")
echo "$RESPONSE" | python -m json.tool
echo ""
REQUEST_ID=$(echo "$RESPONSE" | python -c "import sys, json; print(json.load(sys.stdin)['request_id'])" 2>/dev/null || echo "")
if [ -z "$REQUEST_ID" ]; then
echo "βœ— Failed to submit job"
exit 1
fi
echo "βœ“ Job ID: $REQUEST_ID"
echo ""
# Step 3: Poll status
echo "3. Polling Status (will check 5 times, 10s apart)..."
for i in {1..5}; do
echo " Poll $i/5..."
STATUS=$(curl -s "$BASE_URL/jobs/$REQUEST_ID/status")
CURRENT_STATUS=$(echo "$STATUS" | python -c "import sys, json; print(json.load(sys.stdin)['status'])" 2>/dev/null || echo "unknown")
echo " Status: $CURRENT_STATUS"
if [ "$CURRENT_STATUS" = "completed" ]; then
echo ""
echo "βœ“ JOB COMPLETED!"
echo "$STATUS" | python -m json.tool
exit 0
elif [ "$CURRENT_STATUS" = "failed" ]; then
echo ""
echo "βœ— JOB FAILED"
echo "$STATUS" | python -m json.tool
exit 1
fi
if [ $i -lt 5 ]; then
sleep 10
fi
done
echo ""
echo "⏱ Job still in progress. Continue polling manually:"
echo " curl $BASE_URL/jobs/$REQUEST_ID/status"
echo ""
echo "Or use the full test script:"
echo " python test_async_api.py --google-token $GOOGLE_TOKEN"