ArrcttacsrjksX commited on
Commit
464cc1a
·
verified ·
1 Parent(s): fced557

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -7
app.py CHANGED
@@ -1,10 +1,45 @@
1
  import gradio as gr
2
- from engine import text_to_image, extract_and_load_fonts_from_directory, get_system_fonts
 
 
3
 
4
- # Extract fonts from all zip files in the "fontfile" directory
5
- extracted_fonts = extract_and_load_fonts_from_directory("fontfile")
6
- system_fonts = get_system_fonts()
7
- all_fonts = extracted_fonts + system_fonts
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  with gr.Blocks() as demo:
10
  gr.Markdown("# 🖼️ Text to Image Converter")
@@ -15,7 +50,7 @@ with gr.Blocks() as demo:
15
 
16
  with gr.Row():
17
  font_size = gr.Slider(10, 100, value=30, label="Font Size")
18
- font_name = gr.Dropdown(choices=all_fonts, value=all_fonts[0], label="Font")
19
  align = gr.Radio(["Left", "Center", "Right"], label="Text Alignment", value="Center")
20
 
21
  with gr.Row():
@@ -40,7 +75,7 @@ with gr.Blocks() as demo:
40
  file_convert_button = gr.Button("Convert File to Image")
41
 
42
  convert_button.click(
43
- text_to_image,
44
  inputs=[
45
  input_text, font_size, width, height, bg_color, text_color,
46
  mode, font_name, align, line_spacing, image_format
 
1
  import gradio as gr
2
+ import subprocess
3
+ import json
4
+ import os
5
 
6
+ # Path to the compiled engine executable
7
+ ENGINE_EXECUTABLE = "engine.exe"
8
+
9
+ def call_engine(input_text, font_size, width, height, bg_color, text_color, mode, font_name, align, line_spacing, image_format):
10
+ # Prepare input data as a dictionary
11
+ input_data = {
12
+ "input_text": input_text,
13
+ "font_size": font_size,
14
+ "width": width,
15
+ "height": height,
16
+ "bg_color": bg_color,
17
+ "text_color": text_color,
18
+ "mode": mode,
19
+ "font_path": font_name,
20
+ "align": align,
21
+ "line_spacing": line_spacing,
22
+ "image_format": image_format
23
+ }
24
+
25
+ # Convert input data to JSON string
26
+ input_json = json.dumps(input_data)
27
+
28
+ # Call the engine executable with input data
29
+ result = subprocess.run(
30
+ [ENGINE_EXECUTABLE, input_json],
31
+ capture_output=True,
32
+ text=True
33
+ )
34
+
35
+ # Get the output image path from stdout
36
+ output_path = result.stdout.strip()
37
+
38
+ # Load the generated image
39
+ if os.path.exists(output_path):
40
+ return output_path
41
+ else:
42
+ raise Exception("Failed to generate image!")
43
 
44
  with gr.Blocks() as demo:
45
  gr.Markdown("# 🖼️ Text to Image Converter")
 
50
 
51
  with gr.Row():
52
  font_size = gr.Slider(10, 100, value=30, label="Font Size")
53
+ font_name = gr.Dropdown(choices=[], value="", label="Font") # Populate dynamically
54
  align = gr.Radio(["Left", "Center", "Right"], label="Text Alignment", value="Center")
55
 
56
  with gr.Row():
 
75
  file_convert_button = gr.Button("Convert File to Image")
76
 
77
  convert_button.click(
78
+ call_engine,
79
  inputs=[
80
  input_text, font_size, width, height, bg_color, text_color,
81
  mode, font_name, align, line_spacing, image_format