Spaces:
Running
Running
Deniel Dimitrov
commited on
Commit
Β·
86cfa7a
1
Parent(s):
f977167
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,7 @@
|
|
1 |
-
import gradio as gr
|
2 |
from PIL import Image
|
3 |
-
import
|
4 |
|
5 |
def convert_to_ascii(image, text_size):
|
6 |
-
image = Image.fromarray(image.astype('uint8'))
|
7 |
-
|
8 |
width, height = image.size
|
9 |
aspect_ratio = height / width
|
10 |
new_width = int(text_size)
|
@@ -13,7 +10,7 @@ def convert_to_ascii(image, text_size):
|
|
13 |
resized_image = image.resize((new_width, new_height))
|
14 |
grayscale_image = resized_image.convert('L')
|
15 |
|
16 |
-
ascii_chars = 'β@&%#*β+=-:,.\/|][}{)(
|
17 |
|
18 |
ascii_image = ''
|
19 |
for y in range(new_height):
|
@@ -27,10 +24,19 @@ def convert_to_ascii(image, text_size):
|
|
27 |
|
28 |
return ascii_image
|
29 |
|
30 |
-
def image_to_ascii(
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
-
iface = gr.Interface(fn=image_to_ascii, inputs=["image", "number"], outputs="text", title="Image to ASCII")
|
35 |
iface.launch()
|
36 |
-
|
|
|
|
|
1 |
from PIL import Image
|
2 |
+
import gradio as gr
|
3 |
|
4 |
def convert_to_ascii(image, text_size):
|
|
|
|
|
5 |
width, height = image.size
|
6 |
aspect_ratio = height / width
|
7 |
new_width = int(text_size)
|
|
|
10 |
resized_image = image.resize((new_width, new_height))
|
11 |
grayscale_image = resized_image.convert('L')
|
12 |
|
13 |
+
ascii_chars = 'β@&%#*β+=-:,.\/|][}{)(Β΄ββ ' # add more characters if you want
|
14 |
|
15 |
ascii_image = ''
|
16 |
for y in range(new_height):
|
|
|
24 |
|
25 |
return ascii_image
|
26 |
|
27 |
+
def image_to_ascii(img):
|
28 |
+
image = Image.open(img.name)
|
29 |
+
text_size = int(img_size)
|
30 |
+
ascii_art = convert_to_ascii(image, text_size)
|
31 |
+
return ascii_art
|
32 |
+
|
33 |
+
iface = gr.Interface(
|
34 |
+
fn=image_to_ascii,
|
35 |
+
inputs=gr.inputs.Image(label="Upload Image"),
|
36 |
+
outputs=gr.outputs.Textbox(label="ASCII Art"),
|
37 |
+
title="Image to ASCII Art",
|
38 |
+
description="Upload an image and convert it to ASCII art."
|
39 |
+
)
|
40 |
|
|
|
41 |
iface.launch()
|
42 |
+
|