File size: 1,886 Bytes
fbf5e14
66f8fc1
41e193d
6987040
 
 
 
41e193d
 
6987040
 
 
 
 
 
 
 
72d6681
 
6987040
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1a1b115
72d6681
6987040
 
 
5ce139d
 
e8f2900
5ce139d
e8f2900
 
 
 
5ce139d
e8f2900
 
 
 
ffcf10e
e8f2900
 
c7eed2a
 
 
c1f1f88
e8f2900
66f8fc1
6987040
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

import gradio as gr
import numpy as np
from PIL import Image

def generate_ascii_art(image):
    try:
        # Convert the numpy array to a PIL Image
        img = Image.fromarray(np.uint8(image))

        # Resize the image to a smaller size for faster processing
        img = img.resize((80, 60))

        # Convert the image to grayscale
        img = img.convert("L")

        # Define ASCII characters to represent different intensity levels
        #ascii_chars = "@%#*+=-:. "
        ascii_chars = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/|()1{}[]?-_+~<>i!lI;:,\\^`'. "

        # Convert each pixel to ASCII character based on intensity
        ascii_image = ""
        for pixel_value in img.getdata():
            ascii_image += ascii_chars[pixel_value // 25]

        # Reshape the ASCII string to match the resized image dimensions
        ascii_image = "\n".join([ascii_image[i:i + img.width] for i in range(0, len(ascii_image), img.width)])

        return ascii_image
    except Exception as e:
        return f"Error: {e}"

iface = gr.Interface(
    fn=generate_ascii_art,
    inputs="image",
    outputs="text",
    title="ASCII Art Generator",
    description="Upload an image, and this app will turn it into ASCII art!",
    live=True
)

iface.launch(server_name="0.0.0.0", server_port=7860)


'''
import gradio as gr
import subprocess

def run_command(command):
    try:
        result = subprocess.check_output(command, shell=True, text=True)
        return result
    except subprocess.CalledProcessError as e:
        return f"Error: {e}"

iface = gr.Interface(
    fn=run_command,
    inputs="text",
    outputs="text",
    #live=True,
    title="Command Output Viewer",
    description="Enter a command and view its output.",
    examples=[
    ["ls"],
    ["pwd"],
    ["echo 'Hello, Gradio!'"]]
)

iface.launch(server_name="0.0.0.0", server_port=7860)
'''