Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -552,10 +552,10 @@ def _render_preview(otf_path, font_name):
|
|
| 552 |
try:
|
| 553 |
from PIL import Image, ImageDraw, ImageFont
|
| 554 |
sample = f"{font_name}\nAa Bb Cc 123\nThe quick brown fox"
|
| 555 |
-
img = Image.new("RGB", (
|
| 556 |
draw = ImageDraw.Draw(img)
|
| 557 |
-
font = ImageFont.truetype(otf_path,
|
| 558 |
-
draw.multiline_text((40,
|
| 559 |
return img
|
| 560 |
except Exception as e:
|
| 561 |
print(f"⚠️ Preview failed: {e}")
|
|
@@ -594,8 +594,7 @@ def generate(prompt, control_image, progress=gr.Progress(track_tqdm=True)):
|
|
| 594 |
|
| 595 |
gallery = [(img1, "Uppercase"), (img2, "Lowercase"), (img3, "Punctuation")]
|
| 596 |
preview = _render_preview(otf_path, font_name)
|
| 597 |
-
|
| 598 |
-
return gallery, preview, otf_path, status
|
| 599 |
|
| 600 |
|
| 601 |
# =============================================================================
|
|
@@ -842,30 +841,7 @@ CSS = """
|
|
| 842 |
#otf-file .unpadded_box, #otf-file .empty { min-height: 56px !important; height: 56px !important; }
|
| 843 |
#preview-img .unpadded_box, #preview-img .empty { min-height: 96px !important; }
|
| 844 |
|
| 845 |
-
/*
|
| 846 |
-
.status-line { min-height: 22px; }
|
| 847 |
-
.status-line p {
|
| 848 |
-
font-family: var(--grotesk) !important;
|
| 849 |
-
font-size: 13px !important;
|
| 850 |
-
color: var(--ink) !important;
|
| 851 |
-
margin: 0 !important;
|
| 852 |
-
letter-spacing: 0.02em;
|
| 853 |
-
}
|
| 854 |
-
.status-line b { font-weight: 700; }
|
| 855 |
-
.status-line code {
|
| 856 |
-
font-family: var(--mono);
|
| 857 |
-
font-size: 12px;
|
| 858 |
-
color: var(--ink);
|
| 859 |
-
background: transparent;
|
| 860 |
-
}
|
| 861 |
-
.status-line .sep { color: var(--grey); margin: 0 8px; }
|
| 862 |
-
.status-line .dot {
|
| 863 |
-
display: inline-block;
|
| 864 |
-
width: 9px; height: 9px;
|
| 865 |
-
background: var(--red);
|
| 866 |
-
margin-right: 10px;
|
| 867 |
-
vertical-align: baseline;
|
| 868 |
-
}
|
| 869 |
|
| 870 |
/* Progress bar in red, flat — single gauge inside the grids block */
|
| 871 |
.gradio-container .progress-bar { background: var(--red) !important; }
|
|
@@ -913,15 +889,14 @@ with gr.Blocks(title="Typotopia", theme=THEME, css=CSS) as demo:
|
|
| 913 |
btn = gr.Button("Generate font", variant="primary", elem_classes=["go-btn"])
|
| 914 |
with gr.Column(scale=1):
|
| 915 |
gr.HTML("<p class='eyebrow'><span class='idx'>02</span>Specimen</p>")
|
| 916 |
-
status = gr.HTML(elem_classes=["status-line"])
|
| 917 |
otf_file = gr.File(label="Download .otf", height=56, elem_id="otf-file")
|
| 918 |
-
preview = gr.Image(label="Preview", type="pil", height=
|
| 919 |
gallery = gr.Gallery(label="Generated grids", columns=3, height=150, object_fit="contain", elem_id="grids")
|
| 920 |
|
| 921 |
btn.click(
|
| 922 |
generate,
|
| 923 |
inputs=[prompt, control_image],
|
| 924 |
-
outputs=[gallery, preview, otf_file
|
| 925 |
show_progress="full",
|
| 926 |
show_progress_on=gallery,
|
| 927 |
)
|
|
|
|
| 552 |
try:
|
| 553 |
from PIL import Image, ImageDraw, ImageFont
|
| 554 |
sample = f"{font_name}\nAa Bb Cc 123\nThe quick brown fox"
|
| 555 |
+
img = Image.new("RGB", (1700, 620), "white")
|
| 556 |
draw = ImageDraw.Draw(img)
|
| 557 |
+
font = ImageFont.truetype(otf_path, 150)
|
| 558 |
+
draw.multiline_text((40, 30), sample, font=font, fill="black", spacing=30)
|
| 559 |
return img
|
| 560 |
except Exception as e:
|
| 561 |
print(f"⚠️ Preview failed: {e}")
|
|
|
|
| 594 |
|
| 595 |
gallery = [(img1, "Uppercase"), (img2, "Lowercase"), (img3, "Punctuation")]
|
| 596 |
preview = _render_preview(otf_path, font_name)
|
| 597 |
+
return gallery, preview, otf_path
|
|
|
|
| 598 |
|
| 599 |
|
| 600 |
# =============================================================================
|
|
|
|
| 841 |
#otf-file .unpadded_box, #otf-file .empty { min-height: 56px !important; height: 56px !important; }
|
| 842 |
#preview-img .unpadded_box, #preview-img .empty { min-height: 96px !important; }
|
| 843 |
|
| 844 |
+
/* Progress bar in red, flat — single gauge inside the grids block */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 845 |
|
| 846 |
/* Progress bar in red, flat — single gauge inside the grids block */
|
| 847 |
.gradio-container .progress-bar { background: var(--red) !important; }
|
|
|
|
| 889 |
btn = gr.Button("Generate font", variant="primary", elem_classes=["go-btn"])
|
| 890 |
with gr.Column(scale=1):
|
| 891 |
gr.HTML("<p class='eyebrow'><span class='idx'>02</span>Specimen</p>")
|
|
|
|
| 892 |
otf_file = gr.File(label="Download .otf", height=56, elem_id="otf-file")
|
| 893 |
+
preview = gr.Image(label="Preview", type="pil", height=150, elem_id="preview-img")
|
| 894 |
gallery = gr.Gallery(label="Generated grids", columns=3, height=150, object_fit="contain", elem_id="grids")
|
| 895 |
|
| 896 |
btn.click(
|
| 897 |
generate,
|
| 898 |
inputs=[prompt, control_image],
|
| 899 |
+
outputs=[gallery, preview, otf_file],
|
| 900 |
show_progress="full",
|
| 901 |
show_progress_on=gallery,
|
| 902 |
)
|