fokan commited on
Commit
e15716d
·
verified ·
1 Parent(s): 93859d5

Upload 49 files

Browse files
Files changed (5) hide show
  1. CHANGES_SUMMARY.md +3 -3
  2. Dockerfile +21 -4
  3. app.py +5 -5
  4. arabic_fonts_setup.sh +4 -4
  5. setup_fonts.py +2 -2
CHANGES_SUMMARY.md CHANGED
@@ -17,7 +17,7 @@
17
  def setup_local_arial_font():
18
  """Setup local Arial font from fonts directory"""
19
  # نسخ arial.ttf من مجلد fonts/ إلى النظام
20
- # تثبيت الخط في /usr/share/fonts/truetype/local-arial/
21
  # إعطاء صلاحيات مناسبة للملف
22
  ```
23
 
@@ -56,7 +56,7 @@ def apply_template_font_settings(docx_path, validation_info):
56
  #### تعديل `create_fontconfig()`
57
  ```xml
58
  <!-- إضافة مجلد الخطوط المحلية -->
59
- <dir>/usr/share/fonts/truetype/local-arial</dir>
60
 
61
  <!-- إعطاء أولوية لخط Arial المحلي -->
62
  <alias>
@@ -160,4 +160,4 @@ python app.py
160
  - **حفظ جميع العناصر** (جداول، صور، placeholders)
161
  - **سهولة الاستخدام** مع واجهة Gradio
162
 
163
- النظام جاهز للاستخدام ويحقق جميع المتطلبات المحددة!
 
17
  def setup_local_arial_font():
18
  """Setup local Arial font from fonts directory"""
19
  # نسخ arial.ttf من مجلد fonts/ إلى النظام
20
+ # تثبيت الخط في /tmp/fonts/truetype/local-arial/ لتجنب مشاكل الصلاحيات
21
  # إعطاء صلاحيات مناسبة للملف
22
  ```
23
 
 
56
  #### تعديل `create_fontconfig()`
57
  ```xml
58
  <!-- إضافة مجلد الخطوط المحلية -->
59
+ <dir>/tmp/fonts/truetype/local-arial</dir>
60
 
61
  <!-- إعطاء أولوية لخط Arial المحلي -->
62
  <alias>
 
160
  - **حفظ جميع العناصر** (جداول، صور، placeholders)
161
  - **سهولة الاستخدام** مع واجهة Gradio
162
 
163
+ النظام جاهز للاستخدام ويحقق جميع المتطلبات المحددة!
Dockerfile CHANGED
@@ -43,6 +43,11 @@ RUN locale-gen ar_SA.UTF-8
43
  # Update font cache
44
  RUN fc-cache -fv
45
 
 
 
 
 
 
46
  # Set working directory
47
  WORKDIR /app
48
 
@@ -60,11 +65,23 @@ RUN mkdir -p static
60
  # Copy all remaining files
61
  COPY . .
62
 
63
- # Setup additional Arabic fonts using Python script instead of shell script
64
- RUN python3 setup_fonts.py || echo "Font setup failed, continuing with default fonts..."
 
 
 
 
 
 
65
 
66
- # Pre-initialize LibreOffice to avoid first-run errors
67
- RUN libreoffice --headless --version || true
 
 
 
 
 
 
68
 
69
  # Expose port (Hugging Face Spaces requires port 7860)
70
  EXPOSE 7860
 
43
  # Update font cache
44
  RUN fc-cache -fv
45
 
46
+ # Pre-initialize LibreOffice to avoid first-run errors
47
+ # Run LibreOffice once to complete initial setup
48
+ RUN mkdir -p /tmp/.config/libreoffice && \
49
+ HOME=/tmp libreoffice --headless --version || true
50
+
51
  # Set working directory
52
  WORKDIR /app
53
 
 
65
  # Copy all remaining files
66
  COPY . .
67
 
68
+ # Setup Arabic fonts using conditional script execution to avoid build failures
69
+ # First try the shell script approach (for Hugging Face Spaces compatibility)
70
+ RUN if [ -f "arabic_fonts_setup.sh" ]; then \
71
+ chmod +x arabic_fonts_setup.sh && \
72
+ ./arabic_fonts_setup.sh; \
73
+ else \
74
+ echo "arabic_fonts_setup.sh not found, skipping font setup"; \
75
+ fi
76
 
77
+ # Fallback to Python script approach if shell script fails or is not found
78
+ # Use /tmp for font installation to avoid permission issues
79
+ RUN sed -i 's|/usr/share/fonts/truetype|/tmp/fonts/truetype|g' setup_fonts.py && \
80
+ mkdir -p /tmp/fonts/truetype && \
81
+ python3 setup_fonts.py || echo "Font setup failed, continuing with default fonts..."
82
+
83
+ # Update font cache after installing additional fonts
84
+ RUN fc-cache -fv
85
 
86
  # Expose port (Hugging Face Spaces requires port 7860)
87
  EXPOSE 7860
app.py CHANGED
@@ -119,8 +119,8 @@ def setup_local_arial_font():
119
  print(f" Looking for: arial.ttf")
120
  return False
121
 
122
- # Create system fonts directory for local Arial
123
- system_fonts_dir = Path("/usr/share/fonts/truetype/local-arial")
124
  system_fonts_dir.mkdir(parents=True, exist_ok=True)
125
 
126
  # Copy Arial font to system directory
@@ -147,8 +147,8 @@ def install_arabic_fonts():
147
  import zipfile
148
  import tempfile
149
 
150
- # Create fonts directory
151
- fonts_dir = Path("/usr/share/fonts/truetype/arabic-custom")
152
  fonts_dir.mkdir(parents=True, exist_ok=True)
153
 
154
  print("🔤 Installing Arabic fonts for RTL support...")
@@ -266,7 +266,7 @@ def create_fontconfig(temp_path):
266
  <dir>~/.fonts</dir>
267
 
268
  <!-- Add local fonts directory (same as Python script) -->
269
- <dir>/usr/share/fonts/truetype/local-arial</dir>
270
  <dir>{script_dir}</dir>
271
 
272
  <!-- Font substitution rules with local Arial as priority -->
 
119
  print(f" Looking for: arial.ttf")
120
  return False
121
 
122
+ # Create system fonts directory for local Arial in /tmp to avoid permission issues
123
+ system_fonts_dir = Path("/tmp/fonts/truetype/local-arial")
124
  system_fonts_dir.mkdir(parents=True, exist_ok=True)
125
 
126
  # Copy Arial font to system directory
 
147
  import zipfile
148
  import tempfile
149
 
150
+ # Create fonts directory in /tmp to avoid permission issues
151
+ fonts_dir = Path("/tmp/fonts/truetype/arabic-custom")
152
  fonts_dir.mkdir(parents=True, exist_ok=True)
153
 
154
  print("🔤 Installing Arabic fonts for RTL support...")
 
266
  <dir>~/.fonts</dir>
267
 
268
  <!-- Add local fonts directory (same as Python script) -->
269
+ <dir>/tmp/fonts/truetype/local-arial</dir>
270
  <dir>{script_dir}</dir>
271
 
272
  <!-- Font substitution rules with local Arial as priority -->
arabic_fonts_setup.sh CHANGED
@@ -6,8 +6,8 @@ set -e
6
 
7
  echo "🔤 Setting up Arabic fonts for perfect RTL support..."
8
 
9
- # Create fonts directory
10
- FONTS_DIR="/usr/share/fonts/truetype/arabic-enhanced"
11
  mkdir -p "$FONTS_DIR"
12
 
13
  # Download and install Amiri font (best for Traditional Arabic)
@@ -34,8 +34,8 @@ fc-cache -fv
34
 
35
  # Verify Arabic fonts installation
36
  echo "✅ Verifying Arabic fonts installation..."
37
- fc-list | grep -i "amiri\|scheherazade\|noto.*arabic" | head -10
38
 
39
  echo "🎯 Arabic fonts setup completed successfully!"
40
  echo "Available Arabic fonts:"
41
- fc-list | grep -i "arabic\|amiri\|scheherazade" | cut -d: -f2 | sort | uniq
 
6
 
7
  echo "🔤 Setting up Arabic fonts for perfect RTL support..."
8
 
9
+ # Create fonts directory in /tmp to avoid permission issues
10
+ FONTS_DIR="/tmp/fonts/truetype/arabic-enhanced"
11
  mkdir -p "$FONTS_DIR"
12
 
13
  # Download and install Amiri font (best for Traditional Arabic)
 
34
 
35
  # Verify Arabic fonts installation
36
  echo "✅ Verifying Arabic fonts installation..."
37
+ fc-list | grep -i "amiri|scheherazade|noto.*arabic" | head -10
38
 
39
  echo "🎯 Arabic fonts setup completed successfully!"
40
  echo "Available Arabic fonts:"
41
+ fc-list | grep -i "arabic|amiri|scheherazade" | cut -d: -f2 | sort | uniq
setup_fonts.py CHANGED
@@ -41,8 +41,8 @@ def setup_arabic_fonts():
41
  """Setup Arabic fonts for LibreOffice"""
42
  print("🔤 Setting up Arabic fonts for RTL support...")
43
 
44
- # Create fonts directory
45
- fonts_dir = "/usr/share/fonts/truetype/arabic-enhanced"
46
  os.makedirs(fonts_dir, exist_ok=True)
47
 
48
  # Try to download and install Amiri font
 
41
  """Setup Arabic fonts for LibreOffice"""
42
  print("🔤 Setting up Arabic fonts for RTL support...")
43
 
44
+ # Use /tmp for font installation to avoid permission issues
45
+ fonts_dir = "/tmp/fonts/truetype/arabic-enhanced"
46
  os.makedirs(fonts_dir, exist_ok=True)
47
 
48
  # Try to download and install Amiri font