3morixd commited on
Commit
5727128
·
verified ·
1 Parent(s): 30d43ba

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +80 -26
app.py CHANGED
@@ -1,8 +1,14 @@
 
 
 
 
 
 
1
  import os
2
  import io
3
  import gradio as gr
4
  from huggingface_hub import InferenceClient
5
- from PIL import Image
6
 
7
  # --- Configuration -----------------------------------------------------------
8
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
@@ -15,11 +21,13 @@ ACCENT = "#1FE0E6"
15
 
16
  # Calligraphy styles
17
  STYLES = {
18
- "Thuluth": "Thuluth script, elegant large sweeping curves, ornate flowing letters, classical",
19
  "Naskh": "Naskh script, clean readable traditional book script, rounded letters, classic",
20
  "Diwani": "Diwani script, decorative curved ornamental Ottoman style, intricate overlapping letters",
21
  "Kufi": "Kufic script, geometric angular blocky letters, strict grid pattern, ancient architectural style",
22
  "Modern": "Modern Arabic calligraphy, contemporary stylized abstract elegant fusion of traditional and modern art",
 
 
23
  }
24
 
25
  # Color schemes: name -> (foreground desc, background desc)
@@ -27,25 +35,39 @@ COLOR_SCHEMES = {
27
  "Gold on Black": ("gold metallic letters", "deep black textured background"),
28
  "White on Blue": ("pure white letters", "rich deep blue gradient background"),
29
  "Silver on Dark": ("silver metallic letters", "dark charcoal gradient background"),
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
31
 
32
  # Example prompts in Arabic
33
  EXAMPLES_AR = [
34
  "بسم الله الرحمن الرحيم",
35
  "السلام عليكم ورحمة الله وبركاته",
36
- "الحب للوطن من اليمان",
37
  "العلم نور",
38
  "صبر جميل",
39
  "توكل على الله",
40
- " Dispatch AI ",
 
 
41
  ]
42
 
43
 
44
- # --- Core function -----------------------------------------------------------
45
- def build_prompt(arabic_text, style, color_scheme):
46
  """Construct a detailed prompt for FLUX."""
47
  style_desc = STYLES.get(style, STYLES["Thuluth"])
48
  fg, bg = COLOR_SCHEMES.get(color_scheme, COLOR_SCHEMES["Gold on Black"])
 
49
 
50
  text = arabic_text.strip() if arabic_text.strip() else "بسم الله"
51
 
@@ -53,15 +75,15 @@ def build_prompt(arabic_text, style, color_scheme):
53
  f"Arabic calligraphy art of the text '{text}', "
54
  f"rendered in {style_desc}, "
55
  f"with {fg} on {bg}, "
56
- f"centered composition, elegant ornamental frame, "
57
  f"high detail, ultra sharp, 4k, luxurious Islamic art style"
58
  )
59
  return prompt
60
 
61
 
62
- def generate_calligraphy(arabic_text, style, color_scheme):
63
  """Generate Arabic calligraphy art via FLUX.1-schnell."""
64
- prompt = build_prompt(arabic_text, style, color_scheme)
65
  w, h = 1024, 1024
66
 
67
  try:
@@ -71,32 +93,58 @@ def generate_calligraphy(arabic_text, style, color_scheme):
71
  return image, "✅ Calligraphy generated!", prompt
72
  except Exception as e:
73
  img = Image.new("RGB", (w, h), BG_COLOR)
 
 
74
  return img, f"❌ Error: {str(e)}", prompt
75
 
76
 
77
  # --- UI -----------------------------------------------------------------------
78
- CUSTOM_CSS = f"""
79
- .gradio-container {{background-color: {BG_COLOR} !important;}}
80
- h1, h2, h3 {{color: {ACCENT} !important;}}
 
 
 
 
 
81
  """
82
 
83
  with gr.Blocks(
84
- title="Dispatch AI Arabic Calligraphy",
85
  theme=gr.themes.Base(
86
  primary_hue="cyan",
 
87
  neutral_hue="slate",
88
- font=("Inter", "system-ui", "sans-serif"),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  ),
90
- css=CUSTOM_CSS,
91
  ) as demo:
92
- gr.Markdown(
93
- f"""
94
- <div style="text-align:center;">
95
- <h1>Dispatch AI Arabic Calligraphy</h1>
96
- <p style="color:{ACCENT};">Generate beautiful Arabic calligraphy art with FLUX.1-schnell · Dispatch AI (FZE)</p>
97
- </div>
98
- """
99
- )
100
 
101
  with gr.Row():
102
  with gr.Column(scale=1):
@@ -117,6 +165,11 @@ with gr.Blocks(
117
  label="Color Scheme",
118
  value="Gold on Black",
119
  )
 
 
 
 
 
120
  generate_btn = gr.Button("✨ Generate Calligraphy", variant="primary")
121
  with gr.Column(scale=2):
122
  output_image = gr.Image(
@@ -137,17 +190,18 @@ with gr.Blocks(
137
  # Events
138
  generate_btn.click(
139
  generate_calligraphy,
140
- inputs=[arabic_input, style_select, color_select],
141
  outputs=[output_image, status_box, prompt_box],
142
  )
143
 
144
  gr.Markdown(
145
  """
146
- <div style="text-align:center; opacity:0.6; padding-top:20px;">
147
- <small>Dispatch AI (FZE) · UAE · Model: FLUX.1-schnell · Arabic Calligraphy Engine</small>
148
  </div>
149
  """
150
  )
151
 
152
  if __name__ == "__main__":
 
153
  demo.launch()
 
1
+ """
2
+ Dispatch AI — Arabic Calligraphy
3
+ Generate Arabic calligraphy art with FLUX.1-schnell.
4
+ Text input, style selector (Thuluth/Naskh/Diwani/Kufi/Modern), color scheme.
5
+ """
6
+
7
  import os
8
  import io
9
  import gradio as gr
10
  from huggingface_hub import InferenceClient
11
+ from PIL import Image, ImageDraw
12
 
13
  # --- Configuration -----------------------------------------------------------
14
  HF_TOKEN = os.environ.get("HF_TOKEN", None)
 
21
 
22
  # Calligraphy styles
23
  STYLES = {
24
+ "Thuluth": "Thuluth script, elegant large sweeping curves, ornate flowing letters, classical Islamic style",
25
  "Naskh": "Naskh script, clean readable traditional book script, rounded letters, classic",
26
  "Diwani": "Diwani script, decorative curved ornamental Ottoman style, intricate overlapping letters",
27
  "Kufi": "Kufic script, geometric angular blocky letters, strict grid pattern, ancient architectural style",
28
  "Modern": "Modern Arabic calligraphy, contemporary stylized abstract elegant fusion of traditional and modern art",
29
+ "Nasta'liq": "Nasta'liq script, elegant Persian-Arabic style with hanging baseline, refined sloping letters",
30
+ "Ruq'ah": "Ruq'ah script, compact fast style with sharp angles, traditional handwriting style",
31
  }
32
 
33
  # Color schemes: name -> (foreground desc, background desc)
 
35
  "Gold on Black": ("gold metallic letters", "deep black textured background"),
36
  "White on Blue": ("pure white letters", "rich deep blue gradient background"),
37
  "Silver on Dark": ("silver metallic letters", "dark charcoal gradient background"),
38
+ "Gold on Green": ("gold letters", "deep emerald green background with Islamic patterns"),
39
+ "White on Maroon": ("pure white letters", "rich maroon red gradient background"),
40
+ "Bronze on Cream": ("bronze letters", "warm cream parchment background"),
41
+ "Neon on Dark": ("glowing neon cyan letters", "dark black background with subtle glow"),
42
+ }
43
+
44
+ # Composition / layout options
45
+ COMPOSITIONS = {
46
+ "Centered": "centered composition, elegant ornamental frame",
47
+ "Circular": "circular medallion composition, decorative border",
48
+ "Panel": "horizontal panel composition, framed like a mosque tile",
49
+ "Freestyle": "freestyle abstract composition, no frame, artistic flow",
50
  }
51
 
52
  # Example prompts in Arabic
53
  EXAMPLES_AR = [
54
  "بسم الله الرحمن الرحيم",
55
  "السلام عليكم ورحمة الله وبركاته",
56
+ "الحب للوطن من الايمان",
57
  "العلم نور",
58
  "صبر جميل",
59
  "توكل على الله",
60
+ "Dispatch AI",
61
+ "الإمارات",
62
+ "العزة للوطن",
63
  ]
64
 
65
 
66
+ def build_prompt(arabic_text, style, color_scheme, composition):
 
67
  """Construct a detailed prompt for FLUX."""
68
  style_desc = STYLES.get(style, STYLES["Thuluth"])
69
  fg, bg = COLOR_SCHEMES.get(color_scheme, COLOR_SCHEMES["Gold on Black"])
70
+ comp_desc = COMPOSITIONS.get(composition, COMPOSITIONS["Centered"])
71
 
72
  text = arabic_text.strip() if arabic_text.strip() else "بسم الله"
73
 
 
75
  f"Arabic calligraphy art of the text '{text}', "
76
  f"rendered in {style_desc}, "
77
  f"with {fg} on {bg}, "
78
+ f"{comp_desc}, "
79
  f"high detail, ultra sharp, 4k, luxurious Islamic art style"
80
  )
81
  return prompt
82
 
83
 
84
+ def generate_calligraphy(arabic_text, style, color_scheme, composition):
85
  """Generate Arabic calligraphy art via FLUX.1-schnell."""
86
+ prompt = build_prompt(arabic_text, style, color_scheme, composition)
87
  w, h = 1024, 1024
88
 
89
  try:
 
93
  return image, "✅ Calligraphy generated!", prompt
94
  except Exception as e:
95
  img = Image.new("RGB", (w, h), BG_COLOR)
96
+ d = ImageDraw.Draw(img)
97
+ d.text((w // 4, h // 2), f"Error: {str(e)[:60]}", fill=ACCENT)
98
  return img, f"❌ Error: {str(e)}", prompt
99
 
100
 
101
  # --- UI -----------------------------------------------------------------------
102
+ CSS = """
103
+ #dispatch-header h1 {
104
+ color: #FFFFFF; font-size: 2.2rem; margin: 0;
105
+ background: linear-gradient(90deg, #1FE0E6 0%, #FFFFFF 60%);
106
+ -webkit-background-clip: text; -webkit-text-fill-color: transparent;
107
+ }
108
+ #dispatch-header p { color: #1FE0E6; font-size: 1.05rem; margin: 6px 0 0 0; }
109
+ .dispatch-footer { text-align: center; color: #8A8F9C; font-size: 0.9rem; padding-top: 8px; }
110
  """
111
 
112
  with gr.Blocks(
113
+ title="Dispatch AI Arabic Calligraphy",
114
  theme=gr.themes.Base(
115
  primary_hue="cyan",
116
+ secondary_hue="cyan",
117
  neutral_hue="slate",
118
+ font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "system-ui"],
119
+ ).set(
120
+ body_background_fill="#0A0F1A",
121
+ body_background_fill_dark="#0A0F1A",
122
+ body_text_color="#FFFFFF",
123
+ body_text_color_dark="#FFFFFF",
124
+ block_background_fill="#0E1424",
125
+ block_background_fill_dark="#0E1424",
126
+ block_border_color="#1FE0E6",
127
+ block_border_width="1px",
128
+ block_label_text_color="#1FE0E6",
129
+ block_title_text_color="#1FE0E6",
130
+ button_primary_background_fill="#1FE0E6",
131
+ button_primary_background_fill_dark="#1FE0E6",
132
+ button_primary_text_color="#0A0F1A",
133
+ button_primary_border_color="#1FE0E6",
134
+ input_background_fill="#0E1424",
135
+ input_background_fill_dark="#0E1424",
136
+ input_border_color="#1FE0E6",
137
+ input_border_width="1px",
138
  ),
139
+ css=CSS,
140
  ) as demo:
141
+ with gr.Column(elem_id="dispatch-header"):
142
+ gr.Markdown(
143
+ """
144
+ # Dispatch AI Arabic Calligraphy
145
+ Generate beautiful Arabic calligraphy art with FLUX.1-schnell · Dispatch AI (FZE) · UAE
146
+ """
147
+ )
 
148
 
149
  with gr.Row():
150
  with gr.Column(scale=1):
 
165
  label="Color Scheme",
166
  value="Gold on Black",
167
  )
168
+ composition_select = gr.Dropdown(
169
+ list(COMPOSITIONS.keys()),
170
+ label="Composition / Layout",
171
+ value="Centered",
172
+ )
173
  generate_btn = gr.Button("✨ Generate Calligraphy", variant="primary")
174
  with gr.Column(scale=2):
175
  output_image = gr.Image(
 
190
  # Events
191
  generate_btn.click(
192
  generate_calligraphy,
193
+ inputs=[arabic_input, style_select, color_select, composition_select],
194
  outputs=[output_image, status_box, prompt_box],
195
  )
196
 
197
  gr.Markdown(
198
  """
199
+ <div class="dispatch-footer">
200
+ © 2026 Dispatch AI (FZE) · UAE · License 10818 · Model: FLUX.1-schnell · Arabic Calligraphy Engine
201
  </div>
202
  """
203
  )
204
 
205
  if __name__ == "__main__":
206
+ demo.queue()
207
  demo.launch()