Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,11 +8,13 @@ def convert_to_ascii(image, text_size):
|
|
8 |
elif isinstance(image, np.ndarray):
|
9 |
gimage = Image.fromarray(image)
|
10 |
else:
|
11 |
-
|
12 |
|
13 |
-
|
14 |
width, height = gimage.size
|
15 |
-
|
|
|
|
|
|
|
16 |
new_width = int(text_size)
|
17 |
new_height = int(aspect_ratio * text_size * 0.5)
|
18 |
|
@@ -25,7 +27,7 @@ def convert_to_ascii(image, text_size):
|
|
25 |
for y in range(new_height):
|
26 |
for x in range(new_width):
|
27 |
pixel_value = grayscale_image.getpixel((x, y))
|
28 |
-
if pixel_value == 255:
|
29 |
ascii_image += ' '
|
30 |
else:
|
31 |
ascii_image += ascii_chars[int(pixel_value / 255 * (len(ascii_chars) - 1))]
|
@@ -36,6 +38,7 @@ def convert_to_ascii(image, text_size):
|
|
36 |
|
37 |
|
38 |
|
|
|
39 |
# Create an Interface with a title
|
40 |
iface = gr.Interface(
|
41 |
fn=convert_to_ascii, # Function to run
|
|
|
8 |
elif isinstance(image, np.ndarray):
|
9 |
gimage = Image.fromarray(image)
|
10 |
else:
|
11 |
+
raise ValueError("Unsupported input type. Please provide a file path or a NumPy array.")
|
12 |
|
|
|
13 |
width, height = gimage.size
|
14 |
+
|
15 |
+
# Calculate a new aspect ratio based on text_size and original image dimensions
|
16 |
+
aspect_ratio = height / (width * 2) # Adjusted aspect ratio
|
17 |
+
|
18 |
new_width = int(text_size)
|
19 |
new_height = int(aspect_ratio * text_size * 0.5)
|
20 |
|
|
|
27 |
for y in range(new_height):
|
28 |
for x in range(new_width):
|
29 |
pixel_value = grayscale_image.getpixel((x, y))
|
30 |
+
if pixel_value == 255:
|
31 |
ascii_image += ' '
|
32 |
else:
|
33 |
ascii_image += ascii_chars[int(pixel_value / 255 * (len(ascii_chars) - 1))]
|
|
|
38 |
|
39 |
|
40 |
|
41 |
+
|
42 |
# Create an Interface with a title
|
43 |
iface = gr.Interface(
|
44 |
fn=convert_to_ascii, # Function to run
|