Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -78,7 +78,7 @@ def load_model():
|
|
| 78 |
return model
|
| 79 |
|
| 80 |
@spaces.GPU
|
| 81 |
-
def generate_handwriting(style_image, style_text, gen_text, cfg_scale=1.
|
| 82 |
"""
|
| 83 |
Generate handwriting based on style image and generation text
|
| 84 |
|
|
@@ -128,7 +128,7 @@ def generate_handwriting(style_image, style_text, gen_text, cfg_scale=1.0, max_t
|
|
| 128 |
gen_img=None,
|
| 129 |
style_len=style_len,
|
| 130 |
gen_len=None,
|
| 131 |
-
max_img_len=
|
| 132 |
)
|
| 133 |
|
| 134 |
# Generate
|
|
@@ -137,7 +137,7 @@ def generate_handwriting(style_image, style_text, gen_text, cfg_scale=1.0, max_t
|
|
| 137 |
style_text=[style_text if style_text else ""],
|
| 138 |
gen_text=[gen_text],
|
| 139 |
cfg_scale=cfg_scale,
|
| 140 |
-
max_new_tokens=
|
| 141 |
)
|
| 142 |
|
| 143 |
# Convert to PIL Image
|
|
@@ -210,23 +210,14 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 210 |
value="Hello World!"
|
| 211 |
)
|
| 212 |
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
)
|
| 222 |
-
max_tokens = gr.Slider(
|
| 223 |
-
minimum=32,
|
| 224 |
-
maximum=256,
|
| 225 |
-
value=128,
|
| 226 |
-
step=32,
|
| 227 |
-
label="Max Tokens",
|
| 228 |
-
info="Maximum length of generated text"
|
| 229 |
-
)
|
| 230 |
|
| 231 |
generate_btn = gr.Button("Generate ✨", variant="primary", size="lg")
|
| 232 |
|
|
@@ -240,19 +231,19 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 240 |
# Examples with sample images
|
| 241 |
gr.Examples(
|
| 242 |
examples=[
|
| 243 |
-
["example_images/handwritten_1.png", "", "
|
| 244 |
-
["example_images/handwritten_2.png", "", "
|
| 245 |
-
["example_images/
|
| 246 |
-
[
|
| 247 |
],
|
| 248 |
-
inputs=[style_image_input, style_text_input, gen_text_input, cfg_scale
|
| 249 |
label="Example Styles"
|
| 250 |
)
|
| 251 |
|
| 252 |
# Connect the generation function
|
| 253 |
generate_btn.click(
|
| 254 |
fn=generate_handwriting,
|
| 255 |
-
inputs=[style_image_input, style_text_input, gen_text_input, cfg_scale
|
| 256 |
outputs=[output_image, status_text]
|
| 257 |
)
|
| 258 |
|
|
|
|
| 78 |
return model
|
| 79 |
|
| 80 |
@spaces.GPU
|
| 81 |
+
def generate_handwriting(style_image, style_text, gen_text, cfg_scale=1.5):
|
| 82 |
"""
|
| 83 |
Generate handwriting based on style image and generation text
|
| 84 |
|
|
|
|
| 128 |
gen_img=None,
|
| 129 |
style_len=style_len,
|
| 130 |
gen_len=None,
|
| 131 |
+
max_img_len=128 * 8
|
| 132 |
)
|
| 133 |
|
| 134 |
# Generate
|
|
|
|
| 137 |
style_text=[style_text if style_text else ""],
|
| 138 |
gen_text=[gen_text],
|
| 139 |
cfg_scale=cfg_scale,
|
| 140 |
+
max_new_tokens=128
|
| 141 |
)
|
| 142 |
|
| 143 |
# Convert to PIL Image
|
|
|
|
| 210 |
value="Hello World!"
|
| 211 |
)
|
| 212 |
|
| 213 |
+
cfg_scale = gr.Slider(
|
| 214 |
+
minimum=1.0,
|
| 215 |
+
maximum=5.0,
|
| 216 |
+
value=1.5,
|
| 217 |
+
step=0.1,
|
| 218 |
+
label="CFG Scale",
|
| 219 |
+
info="Higher values = stronger style guidance"
|
| 220 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
|
| 222 |
generate_btn = gr.Button("Generate ✨", variant="primary", size="lg")
|
| 223 |
|
|
|
|
| 231 |
# Examples with sample images
|
| 232 |
gr.Examples(
|
| 233 |
examples=[
|
| 234 |
+
["example_images/handwritten_1.png", "", "The quick brown fox jumps over the lazy dog", 1.5],
|
| 235 |
+
["example_images/handwritten_2.png", "", "Hello from handwritten style!", 1.5],
|
| 236 |
+
["example_images/handwritten_3.png", "", "Artificial Intelligence and Machine Learning", 2.0],
|
| 237 |
+
["example_images/typewritten_1.png", "", "This is typewritten style generation", 1.5],
|
| 238 |
],
|
| 239 |
+
inputs=[style_image_input, style_text_input, gen_text_input, cfg_scale],
|
| 240 |
label="Example Styles"
|
| 241 |
)
|
| 242 |
|
| 243 |
# Connect the generation function
|
| 244 |
generate_btn.click(
|
| 245 |
fn=generate_handwriting,
|
| 246 |
+
inputs=[style_image_input, style_text_input, gen_text_input, cfg_scale],
|
| 247 |
outputs=[output_image, status_text]
|
| 248 |
)
|
| 249 |
|