Spaces:
Sleeping
Sleeping
import gradio as gr | |
__font = ["Times New Roman", "Wide Latin", "Rockwell Extra Bold", "Segoe UI Semibold", "MV Boli", | |
"Matura MT Script Capitals", "Microsoft Sans Serif", "Gill Sans Ultra Bold", "Cooper Black", "Algerian", | |
"Goudy Stout", "Corbel", "Arial Black", "Calibri", "Berlin Sans FB Demi"] | |
__size = [8, 9, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72] | |
__weight = ["bold", "italic", "normal"] | |
css = ''' | |
.gradio-container{max-width: 700px !important} | |
h1{text-align:center} | |
footer { | |
visibility: hidden | |
} | |
''' | |
def apply_font_style(font_family, font_size, font_weight): | |
sample_text = "AaBbYyZz" | |
styled_text = f""" | |
<div style="font-family: {font_family}; font-size: {font_size}px; font-weight: {font_weight};"> | |
<strong>Font:</strong> {font_family}<br> | |
<strong>Size:</strong> {font_size}px<br> | |
<strong>Weight:</strong> {font_weight}<br><br> | |
{sample_text} | |
</div> | |
""" | |
return styled_text | |
with gr.Blocks(css=css, theme="allenai/gradio-theme") as demo: | |
gr.Markdown("# Font Style") | |
font_dropdown = gr.Dropdown(choices=__font, label="Font", value=__font[0]) | |
weight_dropdown = gr.Dropdown(choices=__weight, label="Font Style", value=__weight[2]) | |
size_slider = gr.Slider(minimum=8, maximum=72, step=1, label="Size", value=__size[0]) | |
apply_button = gr.Button("Apply") | |
output = gr.HTML(label="Styled Text") | |
apply_button.click(fn=apply_font_style, | |
inputs=[font_dropdown, size_slider, weight_dropdown], | |
outputs=output) | |
demo.launch() |