ArrcttacsrjksX commited on
Commit
923bd25
·
verified ·
1 Parent(s): c045d17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -1
app.py CHANGED
@@ -3,12 +3,27 @@ import gradio as gr
3
  import subprocess
4
  import json
5
  import os
 
6
  import zipfile
7
  from PIL import ImageFont
8
  import matplotlib.font_manager
9
 
10
  # Path to the compiled engine executable
11
- ENGINE_EXECUTABLE = "./engine" # File thực thi trên Linux
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  def extract_and_load_fonts_from_directory(directory="fontfile", extract_to="extracted_fonts"):
14
  if not os.path.exists(extract_to):
@@ -54,6 +69,9 @@ def get_available_fonts():
54
  return sorted(all_fonts)
55
 
56
  def call_engine(input_text, font_size, width, height, bg_color, text_color, mode, font_name, align, line_spacing, image_format):
 
 
 
57
  # Prepare input data as a dictionary
58
  input_data = {
59
  "input_text": input_text,
 
3
  import subprocess
4
  import json
5
  import os
6
+ import stat
7
  import zipfile
8
  from PIL import ImageFont
9
  import matplotlib.font_manager
10
 
11
  # Path to the compiled engine executable
12
+ ENGINE_EXECUTABLE = "./engine"
13
+
14
+ def ensure_executable(file_path):
15
+ """
16
+ Đảm bảo rằng file có quyền thực thi.
17
+ Nếu không, cấp quyền thực thi.
18
+ """
19
+ if not os.access(file_path, os.X_OK): # Kiểm tra quyền thực thi
20
+ try:
21
+ # Cấp quyền thực thi
22
+ current_permissions = os.stat(file_path).st_mode
23
+ os.chmod(file_path, current_permissions | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
24
+ print(f"Granted execute permission to {file_path}")
25
+ except Exception as e:
26
+ raise PermissionError(f"Failed to grant execute permission to {file_path}: {e}")
27
 
28
  def extract_and_load_fonts_from_directory(directory="fontfile", extract_to="extracted_fonts"):
29
  if not os.path.exists(extract_to):
 
69
  return sorted(all_fonts)
70
 
71
  def call_engine(input_text, font_size, width, height, bg_color, text_color, mode, font_name, align, line_spacing, image_format):
72
+ # Ensure the engine file is executable
73
+ ensure_executable(ENGINE_EXECUTABLE)
74
+
75
  # Prepare input data as a dictionary
76
  input_data = {
77
  "input_text": input_text,