Sangmin commited on
Commit
d4079fb
·
1 Parent(s): 0a29442

Add font support and documentation files

Browse files
DEPLOYMENT_SUMMARY.md CHANGED
@@ -7,16 +7,35 @@ Your Qwen OCR app is ready for deployment to Hugging Face Spaces!
7
  - **app.py** - Main Gradio application (API-only version, optimized for HF Spaces)
8
  - **requirements.txt** - Minimal dependencies for the app
9
  - **README.md** - Hugging Face Space card with app description
10
- - **deploy.sh** - Automated deployment script
 
11
  - **deploy_instructions.md** - Detailed deployment instructions
12
  - **test_local.py** - Local testing script
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  ## 🎯 Quick Deploy
15
 
16
- ### Option 1: Automated Script (Recommended)
17
  ```bash
18
  cd /Users/sangmin/Developer/Qwen2.5-VL/huggingface-space
19
- ./deploy.sh YOUR_HF_USERNAME qwen-ocr-detection
 
 
 
 
 
20
  ```
21
 
22
  ### Option 2: Manual Web Upload
@@ -25,11 +44,17 @@ cd /Users/sangmin/Developer/Qwen2.5-VL/huggingface-space
25
  3. Upload `app.py`, `requirements.txt`, and `README.md`
26
  4. Wait for automatic deployment
27
 
28
- ### Option 3: Git Commands
29
  ```bash
30
  cd /Users/sangmin/Developer/Qwen2.5-VL/huggingface-space
 
 
31
  huggingface-cli login
32
- huggingface-cli repo create qwen-ocr-detection --type space --space_sdk gradio
 
 
 
 
33
  git init
34
  git add .
35
  git commit -m "Initial commit"
 
7
  - **app.py** - Main Gradio application (API-only version, optimized for HF Spaces)
8
  - **requirements.txt** - Minimal dependencies for the app
9
  - **README.md** - Hugging Face Space card with app description
10
+ - **deploy.sh** - Automated deployment script (updated with better auth handling)
11
+ - **auth_check.sh** - Authentication status checker
12
  - **deploy_instructions.md** - Detailed deployment instructions
13
  - **test_local.py** - Local testing script
14
 
15
+ ## 🔑 Authentication Required!
16
+
17
+ ### First, check your authentication:
18
+ ```bash
19
+ cd /Users/sangmin/Developer/Qwen2.5-VL/huggingface-space
20
+ ./auth_check.sh
21
+ ```
22
+
23
+ ### Get your Hugging Face token:
24
+ 1. Go to https://huggingface.co/settings/tokens
25
+ 2. Create a new token with **WRITE** access (not READ!)
26
+ 3. Copy the token (starts with `hf_...`)
27
+
28
  ## 🎯 Quick Deploy
29
 
30
+ ### Option 1: Automated Script with Token (Recommended)
31
  ```bash
32
  cd /Users/sangmin/Developer/Qwen2.5-VL/huggingface-space
33
+ ./deploy.sh YOUR_HF_USERNAME qwen-ocr-detection YOUR_HF_TOKEN
34
+ ```
35
+
36
+ Example:
37
+ ```bash
38
+ ./deploy.sh Sangmin qwen-ocr-detection hf_xxxxxxxxxxxxxxxxxxxx
39
  ```
40
 
41
  ### Option 2: Manual Web Upload
 
44
  3. Upload `app.py`, `requirements.txt`, and `README.md`
45
  4. Wait for automatic deployment
46
 
47
+ ### Option 3: Manual Git Commands
48
  ```bash
49
  cd /Users/sangmin/Developer/Qwen2.5-VL/huggingface-space
50
+
51
+ # First, login with your token
52
  huggingface-cli login
53
+ # Or set token as environment variable
54
+ export HF_TOKEN=your_token_here
55
+
56
+ # Create Space and push
57
+ huggingface-cli repo create YOUR_USERNAME/qwen-ocr-detection --type space --space_sdk gradio
58
  git init
59
  git add .
60
  git commit -m "Initial commit"
DEPLOY_WITH_FONTS.md ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚀 Complete Deployment Guide with CJK Font Support
2
+
3
+ ## Quick Deploy (All Fixes Included)
4
+
5
+ ### Files Required for Hugging Face Space
6
+ You need these 5 essential files:
7
+
8
+ 1. **`packages.txt`** - System packages (fonts)
9
+ 2. **`requirements.txt`** - Python packages
10
+ 3. **`app.py`** - Main application
11
+ 4. **`app_simple.py`** - Fallback version
12
+ 5. **`README.md`** - Space description
13
+
14
+ ### Deploy Command
15
+ ```bash
16
+ cd /Users/sangmin/Developer/Qwen2.5-VL/huggingface-space
17
+ ./deploy.sh YOUR_USERNAME YOUR_SPACE_NAME YOUR_TOKEN
18
+ ```
19
+
20
+ Example:
21
+ ```bash
22
+ ./deploy.sh Sangmin qwen-ocr-detection hf_xxxxxxxxxxxx
23
+ ```
24
+
25
+ ### Or Update Existing Space
26
+ ```bash
27
+ cd /Users/sangmin/Developer/Qwen2.5-VL/huggingface-space
28
+ ./update_space.sh
29
+ ```
30
+
31
+ ## What Gets Installed
32
+
33
+ ### System Packages (`packages.txt`)
34
+ ```
35
+ fonts-noto-cjk # CJK fonts (Chinese, Japanese, Korean)
36
+ fonts-noto-cjk-extra # Additional CJK fonts
37
+ fonts-noto-color-emoji # Emoji support
38
+ fonts-liberation # Liberation fonts
39
+ fonts-dejavu-core # DejaVu fonts
40
+ ```
41
+
42
+ ### Python Packages (`requirements.txt`)
43
+ ```
44
+ gradio==4.19.2 # Stable Gradio version
45
+ Pillow>=10.0.0 # Image processing
46
+ openai>=1.0.0 # API client
47
+ ```
48
+
49
+ ## How Hugging Face Processes These Files
50
+
51
+ 1. **Build Phase**:
52
+ - Reads `packages.txt` → runs `apt-get install` for each package
53
+ - Reads `requirements.txt` → runs `pip install` for each package
54
+ - Installs fonts to `/usr/share/fonts/`
55
+
56
+ 2. **Runtime**:
57
+ - App starts with all fonts available
58
+ - Font paths are Linux-specific (not macOS)
59
+ - App searches multiple paths for fonts
60
+
61
+ ## Verification After Deployment
62
+
63
+ ### Check Build Logs
64
+ Look for:
65
+ ```
66
+ Installing apt packages from packages.txt
67
+ Reading package lists...
68
+ Setting up fonts-noto-cjk (1:20201206-1) ...
69
+ ```
70
+
71
+ ### Check App Logs
72
+ Look for:
73
+ ```
74
+ ✅ Loaded font: /usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc
75
+ ```
76
+
77
+ ### Test CJK Text
78
+ Upload an image with:
79
+ - Japanese: ひらがな、カタカナ、漢字
80
+ - Chinese: 中文测试
81
+ - Korean: 한글 테스트
82
+
83
+ ## Troubleshooting
84
+
85
+ ### If Fonts Don't Load
86
+ 1. **Check packages.txt exists** in your Space
87
+ 2. **Rebuild the Space**: Settings → Factory Reboot
88
+ 3. **Use test_fonts.py** to debug available fonts
89
+
90
+ ### If App Crashes
91
+ 1. **Use app_simple.py**: Change app_file in Settings
92
+ 2. **Check Gradio version**: Must be 4.19.2
93
+ 3. **Verify launch config**: Must include server settings
94
+
95
+ ## Manual Web Deployment
96
+
97
+ If scripts don't work, upload via web:
98
+
99
+ 1. Go to: https://huggingface.co/new-space
100
+ 2. Create Space (Gradio SDK)
101
+ 3. Upload these files:
102
+ - `packages.txt` (IMPORTANT!)
103
+ - `requirements.txt`
104
+ - `app.py`
105
+ - `README.md`
106
+ 4. Wait for build to complete
107
+
108
+ ## Expected Result
109
+
110
+ ✅ App runs without errors
111
+ ✅ Japanese text displays correctly in boxes
112
+ ✅ Chinese text displays correctly in boxes
113
+ ✅ Korean text displays correctly in boxes
114
+ ✅ Bounding boxes align with text
115
+ ✅ Text labels are readable
116
+
117
+ ---
118
+
119
+ **Your OCR app is ready with full CJK support!** 🎌🇨🇳🇰🇷
120
+
121
+ Token: Get from https://huggingface.co/settings/tokens (need WRITE access)
FIX_SUMMARY.md ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🔧 Fixes Applied for Hugging Face Deployment Error
2
+
3
+ ## Problem
4
+ The app crashed on Hugging Face Spaces with:
5
+ - `TypeError: argument of type 'bool' is not iterable` in Gradio's API schema generation
6
+ - `ValueError: When localhost is not accessible, a shareable link must be created`
7
+
8
+ ## Root Causes
9
+ 1. **Gradio version incompatibility** - Version 4.44.1 has a bug with API schema generation
10
+ 2. **Incorrect launch configuration** - Missing proper server settings for HF Spaces
11
+
12
+ ## Solutions Implemented
13
+
14
+ ### 1. Updated `requirements.txt`
15
+ ```diff
16
+ - gradio==4.44.1
17
+ + gradio==4.19.2 # Stable version for HF Spaces
18
+ - Pillow==10.4.0
19
+ + Pillow>=10.0.0 # More flexible versioning
20
+ - openai==1.51.0
21
+ + openai>=1.0.0 # More flexible versioning
22
+ ```
23
+
24
+ ### 2. Fixed `app.py` Launch Configuration
25
+ ```diff
26
+ - demo.launch()
27
+ + demo.queue(max_size=20).launch(server_name="0.0.0.0", server_port=7860)
28
+ ```
29
+
30
+ ### 3. Created `app_simple.py` (Fallback)
31
+ - Simplified version without complex features
32
+ - Minimal dependencies
33
+ - More robust error handling
34
+
35
+ ## To Deploy the Fixes
36
+
37
+ ### Quick Update (if already deployed):
38
+ ```bash
39
+ cd /Users/sangmin/Developer/Qwen2.5-VL/huggingface-space
40
+ ./update_space.sh
41
+ ```
42
+
43
+ ### Fresh Deployment:
44
+ ```bash
45
+ cd /Users/sangmin/Developer/Qwen2.5-VL/huggingface-space
46
+ ./deploy.sh YOUR_USERNAME YOUR_SPACE_NAME YOUR_TOKEN
47
+ ```
48
+
49
+ ### Manual Update (via web):
50
+ 1. Go to your Space
51
+ 2. Edit `requirements.txt` with new versions
52
+ 3. Edit `app.py` with new launch configuration
53
+ 4. Commit changes
54
+
55
+ ## Files Updated/Created
56
+ - ✅ `app.py` - Fixed launch configuration
57
+ - ✅ `requirements.txt` - Downgraded Gradio to stable version
58
+ - ✅ `app_simple.py` - Simplified fallback version
59
+ - ✅ `update_space.sh` - Script to push fixes
60
+ - ✅ `TROUBLESHOOTING.md` - Complete troubleshooting guide
61
+ - ✅ `FIX_SUMMARY.md` - This summary
62
+
63
+ ## Verification
64
+ After deployment, the app should:
65
+ 1. Start without errors
66
+ 2. Show "Running on local URL: http://0.0.0.0:7860"
67
+ 3. Be accessible at your Space URL
68
+ 4. Accept image uploads and API keys
69
+ 5. Return annotated images with bounding boxes
70
+
71
+ ## If Issues Persist
72
+ Use the simplified version:
73
+ 1. In Space settings, change `app_file` to `app_simple.py`
74
+ 2. The simplified version has fewer dependencies and is more stable
75
+
76
+ ---
77
+ **Status: Ready to deploy fixes!** 🚀
FONT_FIX_SUMMARY.md ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🔤 CJK Font Support for Hugging Face Spaces
2
+
3
+ ## The Solution: `packages.txt`
4
+
5
+ Hugging Face Spaces allows you to install system packages (like fonts) using a special file called `packages.txt`. This file works like `requirements.txt` but for system packages installed via `apt-get`.
6
+
7
+ ## Files Created/Updated
8
+
9
+ ### 1. **`packages.txt`** (NEW)
10
+ ```
11
+ fonts-noto-cjk
12
+ fonts-noto-cjk-extra
13
+ fonts-noto-color-emoji
14
+ fonts-liberation
15
+ fonts-dejavu-core
16
+ ```
17
+
18
+ This tells Hugging Face to run:
19
+ ```bash
20
+ apt-get install fonts-noto-cjk fonts-noto-cjk-extra fonts-noto-color-emoji fonts-liberation fonts-dejavu-core
21
+ ```
22
+
23
+ ### 2. **Updated `app.py`** and **`app_simple.py`**
24
+ - Added proper Linux font paths
25
+ - Added font loading verification
26
+ - Added fallback handling
27
+
28
+ ## How It Works
29
+
30
+ 1. **During Build**: HF Spaces reads `packages.txt` and installs the listed packages
31
+ 2. **Font Installation**: The Noto CJK fonts get installed to `/usr/share/fonts/`
32
+ 3. **App Runtime**: The app searches for fonts in the correct Linux paths
33
+ 4. **CJK Support**: Japanese, Chinese, and Korean text will display correctly in bounding boxes
34
+
35
+ ## Font Paths on Hugging Face Spaces (Linux)
36
+
37
+ ```python
38
+ font_paths = [
39
+ # Primary CJK fonts
40
+ "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
41
+ "/usr/share/fonts/truetype/noto-cjk/NotoSansCJK-Regular.ttc",
42
+
43
+ # Fallback fonts
44
+ "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
45
+ "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
46
+ ]
47
+ ```
48
+
49
+ ## To Deploy with Font Support
50
+
51
+ ### Option 1: Update Existing Space
52
+ ```bash
53
+ cd /Users/sangmin/Developer/Qwen2.5-VL/huggingface-space
54
+ ./update_space.sh
55
+ ```
56
+
57
+ ### Option 2: Manual Upload
58
+ Upload these 4 files to your Space:
59
+ 1. `packages.txt` - System packages to install
60
+ 2. `requirements.txt` - Python packages
61
+ 3. `app.py` - Updated main app
62
+ 4. `app_simple.py` - Updated simple version
63
+
64
+ ### Option 3: Fresh Deploy
65
+ ```bash
66
+ ./deploy.sh YOUR_USERNAME YOUR_SPACE YOUR_TOKEN
67
+ ```
68
+
69
+ ## Verification
70
+
71
+ After deployment, check the build logs for:
72
+ ```
73
+ Installing apt packages from packages.txt
74
+ Reading package lists...
75
+ Setting up fonts-noto-cjk...
76
+ ```
77
+
78
+ In the app logs, you should see:
79
+ ```
80
+ ✅ Loaded font: /usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc
81
+ ```
82
+
83
+ ## Result
84
+
85
+ ✅ Japanese text (ひらがな、カタカナ、漢字) will display correctly
86
+ ✅ Chinese text (简体/繁體) will display correctly
87
+ ✅ Korean text (한글) will display correctly
88
+ ✅ Emoji and symbols will render properly
89
+
90
+ ## Troubleshooting
91
+
92
+ If fonts still don't work:
93
+ 1. Check build logs for package installation errors
94
+ 2. Try different font paths in the app
95
+ 3. Use `fc-list` command in a debug script to list available fonts
96
+
97
+ ---
98
+
99
+ **The app now has full CJK font support on Hugging Face Spaces!** 🎌🇨🇳🇰🇷
README.md CHANGED
@@ -5,7 +5,7 @@ colorFrom: blue
5
  colorTo: green
6
  sdk: gradio
7
  sdk_version: 4.44.1
8
- app_file: app.py
9
  pinned: false
10
  license: apache-2.0
11
  ---
@@ -16,9 +16,10 @@ This Gradio app uses Qwen Vision Language Models to detect text in images and dr
16
 
17
  ## Features
18
  - 📝 Automatic text detection with precise bounding boxes
19
- - 🌏 Support for multiple languages including CJK (Chinese, Japanese, Korean)
20
  - 📊 JSON output with exact coordinates and text content
21
  - 🎯 Adjustable prompts for custom detection behavior
 
22
 
23
  ## How to Use
24
  1. Upload an image containing text
 
5
  colorTo: green
6
  sdk: gradio
7
  sdk_version: 4.44.1
8
+ app_file: app_simple.py
9
  pinned: false
10
  license: apache-2.0
11
  ---
 
16
 
17
  ## Features
18
  - 📝 Automatic text detection with precise bounding boxes
19
+ - 🌏 Full support for CJK languages (Chinese, Japanese, Korean) with proper fonts
20
  - 📊 JSON output with exact coordinates and text content
21
  - 🎯 Adjustable prompts for custom detection behavior
22
+ - 🔤 Noto CJK fonts pre-installed for accurate text rendering
23
 
24
  ## How to Use
25
  1. Upload an image containing text
TROUBLESHOOTING.md ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🔧 Troubleshooting Guide for Hugging Face Deployment
2
+
3
+ ## Error: "TypeError: argument of type 'bool' is not iterable"
4
+
5
+ ### Solution Applied:
6
+ 1. **Downgraded Gradio** to stable version 4.19.2
7
+ 2. **Fixed launch configuration** for HF Spaces
8
+ 3. **Created simplified version** (app_simple.py) as fallback
9
+
10
+ ### To Apply Fixes:
11
+
12
+ #### Option 1: Update Existing Space
13
+ ```bash
14
+ cd /Users/sangmin/Developer/Qwen2.5-VL/huggingface-space
15
+ ./update_space.sh
16
+ ```
17
+
18
+ #### Option 2: Manual Update via Web
19
+ 1. Go to your Space: https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE
20
+ 2. Click "Files" tab
21
+ 3. Edit `requirements.txt`:
22
+ ```
23
+ gradio==4.19.2
24
+ Pillow>=10.0.0
25
+ openai>=1.0.0
26
+ ```
27
+ 4. Edit `app.py` - change last line to:
28
+ ```python
29
+ demo.queue(max_size=20).launch(server_name="0.0.0.0", server_port=7860)
30
+ ```
31
+ 5. Commit changes
32
+
33
+ #### Option 3: Use Simplified Version
34
+ If main app still has issues:
35
+ 1. Upload `app_simple.py` to your Space
36
+ 2. Go to Space Settings
37
+ 3. Change `app_file` from `app.py` to `app_simple.py`
38
+ 4. Save changes
39
+
40
+ ## Other Common Issues
41
+
42
+ ### 1. Build Fails
43
+ - Check logs in "Logs" tab
44
+ - Verify requirements.txt syntax
45
+ - Try simplified app version
46
+
47
+ ### 2. App Crashes on Start
48
+ - Check API endpoint is correct
49
+ - Verify Gradio version compatibility
50
+ - Use app_simple.py instead
51
+
52
+ ### 3. Authentication Errors
53
+ - Ensure token has WRITE access
54
+ - Re-run deploy script with token:
55
+ ```bash
56
+ ./deploy.sh USERNAME SPACE_NAME YOUR_TOKEN
57
+ ```
58
+
59
+ ### 4. Image Processing Errors
60
+ - Verify API key is valid
61
+ - Check Dashscope service is accessible
62
+ - Test locally first with test_local.py
63
+
64
+ ## Version Compatibility
65
+
66
+ ### Working Configurations:
67
+ - **Gradio**: 4.19.2 (stable for HF Spaces)
68
+ - **Python**: 3.10 (HF Spaces default)
69
+ - **Pillow**: 10.0.0+
70
+ - **OpenAI**: 1.0.0+
71
+
72
+ ### Known Incompatible Versions:
73
+ - Gradio 4.44.1 (API schema bug)
74
+ - Gradio 4.40+ (may have compatibility issues)
75
+
76
+ ## Testing Locally
77
+
78
+ Before deploying, always test:
79
+ ```bash
80
+ cd /Users/sangmin/Developer/Qwen2.5-VL/huggingface-space
81
+ python test_local.py
82
+ # Or test the simple version:
83
+ python app_simple.py
84
+ ```
85
+
86
+ ## Still Having Issues?
87
+
88
+ 1. **Check HF Status**: https://status.huggingface.co/
89
+ 2. **Try Different Region**: Some regions may have better connectivity
90
+ 3. **Use Simplified App**: app_simple.py has fewer dependencies
91
+ 4. **Manual Deployment**: Upload files directly via web interface
92
+
93
+ ## Contact & Support
94
+
95
+ - Hugging Face Discord: https://discord.gg/huggingface
96
+ - Hugging Face Forums: https://discuss.huggingface.co/
97
+ - Gradio Issues: https://github.com/gradio-app/gradio/issues
auth_check.sh ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Simple script to check Hugging Face authentication status
4
+
5
+ echo "🔍 Checking Hugging Face Authentication Status..."
6
+ echo ""
7
+
8
+ # Check if CLI is installed
9
+ if ! command -v huggingface-cli &> /dev/null; then
10
+ echo "❌ huggingface-cli not installed!"
11
+ echo "Install with: pip install huggingface_hub"
12
+ exit 1
13
+ fi
14
+
15
+ # Check login status
16
+ echo "Running: huggingface-cli whoami"
17
+ echo "----------------------------------------"
18
+
19
+ if huggingface-cli whoami 2>/dev/null; then
20
+ echo "----------------------------------------"
21
+ echo "✅ You are logged in!"
22
+ echo ""
23
+ echo "If deployment still fails, your token might not have WRITE permissions."
24
+ echo "Get a new token at: https://huggingface.co/settings/tokens"
25
+ else
26
+ echo "----------------------------------------"
27
+ echo "❌ Not logged in to Hugging Face!"
28
+ echo ""
29
+ echo "To login, use one of these methods:"
30
+ echo ""
31
+ echo "1. Interactive login:"
32
+ echo " huggingface-cli login"
33
+ echo ""
34
+ echo "2. Token environment variable:"
35
+ echo " export HF_TOKEN=your_token_here"
36
+ echo ""
37
+ echo "3. Pass token to deploy script:"
38
+ echo " ./deploy.sh USERNAME SPACE_NAME your_token_here"
39
+ echo ""
40
+ echo "Get your token (WRITE access) at:"
41
+ echo "https://huggingface.co/settings/tokens"
42
+ fi
deploy.sh CHANGED
@@ -1,19 +1,23 @@
1
  #!/bin/bash
2
 
3
  # Deployment script for Hugging Face Spaces
4
- # Usage: ./deploy.sh YOUR_HF_USERNAME SPACE_NAME
5
 
6
  set -e
7
 
8
  # Check if arguments are provided
9
  if [ $# -lt 2 ]; then
10
- echo "Usage: ./deploy.sh YOUR_HF_USERNAME SPACE_NAME"
11
  echo "Example: ./deploy.sh johndoe qwen-ocr-detection"
 
 
 
12
  exit 1
13
  fi
14
 
15
  HF_USERNAME=$1
16
  SPACE_NAME=$2
 
17
 
18
  echo "🚀 Deploying Qwen OCR Detection to Hugging Face Spaces"
19
  echo "Username: $HF_USERNAME"
@@ -23,14 +27,56 @@ echo ""
23
  # Check if huggingface-cli is installed
24
  if ! command -v huggingface-cli &> /dev/null; then
25
  echo "❌ huggingface-cli not found. Installing..."
26
- pip install huggingface_hub
27
  fi
28
 
29
- # Check if logged in
30
- echo "📝 Checking Hugging Face login..."
31
- if ! huggingface-cli whoami &> /dev/null; then
32
- echo "Please login to Hugging Face:"
33
- huggingface-cli login
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  fi
35
 
36
  # Initialize git repository if not already initialized
@@ -43,12 +89,41 @@ fi
43
 
44
  # Create the Space
45
  echo "🏗️ Creating Space on Hugging Face..."
46
- huggingface-cli repo create $SPACE_NAME --type space --space_sdk gradio || echo "Space might already exist, continuing..."
 
 
 
 
 
 
 
47
 
48
- # Add remote and push
49
- echo "📤 Pushing to Hugging Face..."
50
- git remote add origin https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME 2>/dev/null || git remote set-url origin https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME
51
- git push -u origin main --force
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  echo ""
54
  echo "✅ Deployment complete!"
 
1
  #!/bin/bash
2
 
3
  # Deployment script for Hugging Face Spaces
4
+ # Usage: ./deploy.sh YOUR_HF_USERNAME SPACE_NAME [HF_TOKEN]
5
 
6
  set -e
7
 
8
  # Check if arguments are provided
9
  if [ $# -lt 2 ]; then
10
+ echo "Usage: ./deploy.sh YOUR_HF_USERNAME SPACE_NAME [HF_TOKEN]"
11
  echo "Example: ./deploy.sh johndoe qwen-ocr-detection"
12
+ echo " ./deploy.sh johndoe qwen-ocr-detection hf_xxxxxxxxxxxx"
13
+ echo ""
14
+ echo "Get your token at: https://huggingface.co/settings/tokens"
15
  exit 1
16
  fi
17
 
18
  HF_USERNAME=$1
19
  SPACE_NAME=$2
20
+ HF_TOKEN=${3:-$HF_TOKEN} # Use provided token or environment variable
21
 
22
  echo "🚀 Deploying Qwen OCR Detection to Hugging Face Spaces"
23
  echo "Username: $HF_USERNAME"
 
27
  # Check if huggingface-cli is installed
28
  if ! command -v huggingface-cli &> /dev/null; then
29
  echo "❌ huggingface-cli not found. Installing..."
30
+ pip install --upgrade huggingface_hub
31
  fi
32
 
33
+ # Handle authentication
34
+ echo "📝 Checking Hugging Face authentication..."
35
+
36
+ # If token is provided, use it
37
+ if [ ! -z "$HF_TOKEN" ]; then
38
+ echo "Using provided token..."
39
+ export HF_TOKEN=$HF_TOKEN
40
+ # Verify token works
41
+ if ! huggingface-cli whoami 2>/dev/null | grep -q "$HF_USERNAME"; then
42
+ echo "❌ Token authentication failed or username mismatch!"
43
+ echo "Please check your token at: https://huggingface.co/settings/tokens"
44
+ echo "Make sure you're using a WRITE token, not READ."
45
+ exit 1
46
+ fi
47
+ echo "✅ Authentication successful!"
48
+ else
49
+ # Try to check if already logged in
50
+ LOGGED_IN_USER=$(huggingface-cli whoami 2>/dev/null | grep "username:" | awk '{print $2}' || echo "")
51
+
52
+ if [ -z "$LOGGED_IN_USER" ]; then
53
+ echo "❌ Not logged in to Hugging Face!"
54
+ echo ""
55
+ echo "Please login using one of these methods:"
56
+ echo ""
57
+ echo "Option 1: Run with token:"
58
+ echo " ./deploy.sh $HF_USERNAME $SPACE_NAME YOUR_HF_TOKEN"
59
+ echo ""
60
+ echo "Option 2: Login interactively:"
61
+ echo " huggingface-cli login"
62
+ echo ""
63
+ echo "Option 3: Set environment variable:"
64
+ echo " export HF_TOKEN=your_token_here"
65
+ echo ""
66
+ echo "Get your token at: https://huggingface.co/settings/tokens"
67
+ echo "Make sure to use a WRITE token, not READ!"
68
+ exit 1
69
+ elif [ "$LOGGED_IN_USER" != "$HF_USERNAME" ]; then
70
+ echo "⚠️ Warning: Logged in as '$LOGGED_IN_USER' but deploying as '$HF_USERNAME'"
71
+ echo "Continue? (y/n)"
72
+ read -r response
73
+ if [[ ! "$response" =~ ^[Yy]$ ]]; then
74
+ echo "Deployment cancelled."
75
+ exit 1
76
+ fi
77
+ else
78
+ echo "✅ Already logged in as $HF_USERNAME"
79
+ fi
80
  fi
81
 
82
  # Initialize git repository if not already initialized
 
89
 
90
  # Create the Space
91
  echo "🏗️ Creating Space on Hugging Face..."
92
+ SPACE_URL="https://huggingface.co/spaces/$HF_USERNAME/$SPACE_NAME"
93
+
94
+ # Try to create the space (will fail if it already exists, which is OK)
95
+ if huggingface-cli repo create "$HF_USERNAME/$SPACE_NAME" --type space --space_sdk gradio 2>/dev/null; then
96
+ echo "✅ Space created successfully!"
97
+ else
98
+ echo "ℹ️ Space might already exist or creation failed, attempting to push anyway..."
99
+ fi
100
 
101
+ # Configure git remote
102
+ echo "📤 Configuring git remote..."
103
+ if [ ! -z "$HF_TOKEN" ]; then
104
+ # Use token in URL for authentication
105
+ git remote add origin "https://$HF_USERNAME:[email protected]/spaces/$HF_USERNAME/$SPACE_NAME" 2>/dev/null || \
106
+ git remote set-url origin "https://$HF_USERNAME:[email protected]/spaces/$HF_USERNAME/$SPACE_NAME"
107
+ else
108
+ # Use standard URL (will use stored credentials)
109
+ git remote add origin "$SPACE_URL" 2>/dev/null || \
110
+ git remote set-url origin "$SPACE_URL"
111
+ fi
112
+
113
+ # Push to Hugging Face
114
+ echo "📤 Pushing to Hugging Face Spaces..."
115
+ if git push -u origin main --force; then
116
+ echo "✅ Push successful!"
117
+ else
118
+ echo "❌ Push failed!"
119
+ echo ""
120
+ echo "Troubleshooting:"
121
+ echo "1. Check your authentication token has WRITE permissions"
122
+ echo "2. Verify the Space URL: $SPACE_URL"
123
+ echo "3. Try creating the Space manually at: https://huggingface.co/new-space"
124
+ echo "4. Then run: git push -u origin main --force"
125
+ exit 1
126
+ fi
127
 
128
  echo ""
129
  echo "✅ Deployment complete!"
test_fonts.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Test script to check available fonts on Hugging Face Spaces
4
+ Upload this to debug font issues
5
+ """
6
+
7
+ import os
8
+ import subprocess
9
+ from PIL import ImageFont
10
+
11
+ def list_system_fonts():
12
+ """List all available system fonts."""
13
+ print("=== System Fonts ===\n")
14
+
15
+ # Common font directories on Linux
16
+ font_dirs = [
17
+ "/usr/share/fonts",
18
+ "/usr/local/share/fonts",
19
+ "/usr/X11R6/lib/X11/fonts",
20
+ "~/.fonts"
21
+ ]
22
+
23
+ for font_dir in font_dirs:
24
+ expanded_dir = os.path.expanduser(font_dir)
25
+ if os.path.exists(expanded_dir):
26
+ print(f"\n📁 {font_dir}:")
27
+ for root, dirs, files in os.walk(expanded_dir):
28
+ for file in files:
29
+ if file.endswith(('.ttf', '.ttc', '.otf', '.otc')):
30
+ full_path = os.path.join(root, file)
31
+ # Only show CJK related fonts
32
+ if 'cjk' in file.lower() or 'noto' in file.lower() or 'chinese' in file.lower() or 'japanese' in file.lower() or 'korean' in file.lower():
33
+ print(f" ✓ {full_path}")
34
+
35
+ def test_font_loading():
36
+ """Test loading specific fonts."""
37
+ print("\n=== Font Loading Test ===\n")
38
+
39
+ test_paths = [
40
+ "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
41
+ "/usr/share/fonts/truetype/noto-cjk/NotoSansCJK-Regular.ttc",
42
+ "/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc",
43
+ "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
44
+ "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
45
+ ]
46
+
47
+ for font_path in test_paths:
48
+ try:
49
+ font = ImageFont.truetype(font_path, size=14)
50
+ print(f"✅ Successfully loaded: {font_path}")
51
+ except Exception as e:
52
+ print(f"❌ Failed to load: {font_path}")
53
+ print(f" Error: {e}")
54
+
55
+ def check_fc_list():
56
+ """Use fc-list to find CJK fonts."""
57
+ print("\n=== fc-list CJK Fonts ===\n")
58
+
59
+ try:
60
+ result = subprocess.run(['fc-list', ':lang=ja'], capture_output=True, text=True)
61
+ if result.stdout:
62
+ print("Japanese fonts:")
63
+ for line in result.stdout.strip().split('\n')[:5]: # Show first 5
64
+ print(f" {line}")
65
+
66
+ result = subprocess.run(['fc-list', ':lang=zh'], capture_output=True, text=True)
67
+ if result.stdout:
68
+ print("\nChinese fonts:")
69
+ for line in result.stdout.strip().split('\n')[:5]: # Show first 5
70
+ print(f" {line}")
71
+
72
+ result = subprocess.run(['fc-list', ':lang=ko'], capture_output=True, text=True)
73
+ if result.stdout:
74
+ print("\nKorean fonts:")
75
+ for line in result.stdout.strip().split('\n')[:5]: # Show first 5
76
+ print(f" {line}")
77
+ except Exception as e:
78
+ print(f"fc-list not available: {e}")
79
+
80
+ def check_packages():
81
+ """Check if font packages are installed."""
82
+ print("\n=== Installed Font Packages ===\n")
83
+
84
+ packages = ['fonts-noto-cjk', 'fonts-noto-cjk-extra', 'fonts-liberation', 'fonts-dejavu-core']
85
+
86
+ for package in packages:
87
+ try:
88
+ result = subprocess.run(['dpkg', '-l', package], capture_output=True, text=True)
89
+ if result.returncode == 0 and 'ii' in result.stdout:
90
+ print(f"✅ {package} is installed")
91
+ else:
92
+ print(f"❌ {package} is NOT installed")
93
+ except Exception as e:
94
+ print(f"❌ Could not check {package}: {e}")
95
+
96
+ if __name__ == "__main__":
97
+ print("🔍 Font Availability Test for Hugging Face Spaces\n")
98
+ print("=" * 50)
99
+
100
+ check_packages()
101
+ list_system_fonts()
102
+ test_font_loading()
103
+ check_fc_list()
104
+
105
+ print("\n" + "=" * 50)
106
+ print("\n✅ Font test complete!")
107
+ print("\nIf fonts are missing, make sure packages.txt includes:")
108
+ print(" fonts-noto-cjk")
109
+ print(" fonts-noto-cjk-extra")
110
+ print(" fonts-liberation")
111
+ print(" fonts-dejavu-core")
update_space.sh ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+
3
+ # Script to update the Hugging Face Space with fixes
4
+
5
+ echo "🔧 Updating Hugging Face Space with fixes..."
6
+ echo ""
7
+
8
+ # Check if git is initialized
9
+ if [ ! -d .git ]; then
10
+ echo "❌ Not in a git repository. Please run deploy.sh first."
11
+ exit 1
12
+ fi
13
+
14
+ # Add and commit changes
15
+ echo "📦 Committing fixes..."
16
+ git add app.py requirements.txt app_simple.py packages.txt
17
+ git commit -m "Fix: Gradio compatibility and CJK font support
18
+
19
+ - Updated Gradio to stable version 4.19.2
20
+ - Fixed launch configuration for HF Spaces
21
+ - Added packages.txt to install CJK fonts
22
+ - Updated font paths for Linux/HF Spaces
23
+ - Added simplified fallback version (app_simple.py)
24
+ - Relaxed dependency versions for better compatibility"
25
+
26
+ # Push to Hugging Face
27
+ echo "📤 Pushing updates..."
28
+ if git push origin main; then
29
+ echo "✅ Updates pushed successfully!"
30
+ echo ""
31
+ echo "The Space should rebuild automatically. Check the logs on Hugging Face."
32
+ echo ""
33
+ echo "If the main app still has issues, you can switch to app_simple.py:"
34
+ echo "1. Go to your Space settings"
35
+ echo "2. Change 'app_file' from 'app.py' to 'app_simple.py'"
36
+ else
37
+ echo "❌ Push failed. Please check your authentication and try again."
38
+ exit 1
39
+ fi