Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -25,7 +25,11 @@ def add_text_to_image(image_path, text):
|
|
25 |
try:
|
26 |
img = Image.open(image_path)
|
27 |
draw = ImageDraw.Draw(img)
|
28 |
-
font
|
|
|
|
|
|
|
|
|
29 |
lines = textwrap.fill(text, width=40)
|
30 |
draw.text((10, 10), lines, font=font, fill="white", stroke_width=2, stroke_fill="black")
|
31 |
img_with_text = f'text_added_{os.path.basename(image_path)}'
|
@@ -71,7 +75,7 @@ with gr.Blocks() as iface:
|
|
71 |
story_input = gr.Textbox(lines=10, placeholder="Enter your story here...", label="Story Input")
|
72 |
visualize_button = gr.Button("Visualize Story")
|
73 |
|
74 |
-
gallery_output = gr.Gallery(label="Visualized Story", show_label=False, elem_id="gallery"
|
75 |
|
76 |
visualize_button.click(
|
77 |
fn=visualize_story_images,
|
|
|
25 |
try:
|
26 |
img = Image.open(image_path)
|
27 |
draw = ImageDraw.Draw(img)
|
28 |
+
# Use a default font if arial.ttf is not available
|
29 |
+
try:
|
30 |
+
font = ImageFont.truetype("arial.ttf", 20)
|
31 |
+
except IOError:
|
32 |
+
font = ImageFont.load_default()
|
33 |
lines = textwrap.fill(text, width=40)
|
34 |
draw.text((10, 10), lines, font=font, fill="white", stroke_width=2, stroke_fill="black")
|
35 |
img_with_text = f'text_added_{os.path.basename(image_path)}'
|
|
|
75 |
story_input = gr.Textbox(lines=10, placeholder="Enter your story here...", label="Story Input")
|
76 |
visualize_button = gr.Button("Visualize Story")
|
77 |
|
78 |
+
gallery_output = gr.Gallery(label="Visualized Story", show_label=False, elem_id="gallery", columns=2, rows=2, height="auto")
|
79 |
|
80 |
visualize_button.click(
|
81 |
fn=visualize_story_images,
|