ruslanmv commited on
Commit
6987040
1 Parent(s): ffcf10e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +45 -1
main.py CHANGED
@@ -1,4 +1,47 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import subprocess
3
 
4
  def run_command(command):
@@ -21,4 +64,5 @@ iface = gr.Interface(
21
  ["echo 'Hello, Gradio!'"]]
22
  )
23
 
24
- iface.launch(server_name="0.0.0.0", server_port=7860)
 
 
1
  import gradio as gr
2
+ from PIL import Image
3
+
4
+ def generate_ascii_art(image):
5
+ try:
6
+ # Open the image using Pillow
7
+ img = Image.open(image)
8
+
9
+ # Resize the image to a smaller size for faster processing
10
+ img = img.resize((80, 60))
11
+
12
+ # Convert the image to grayscale
13
+ img = img.convert("L")
14
+
15
+ # Define ASCII characters to represent different intensity levels
16
+ ascii_chars = "@%#*+=-:. "
17
+
18
+ # Convert each pixel to ASCII character based on intensity
19
+ ascii_image = ""
20
+ for pixel_value in img.getdata():
21
+ ascii_image += ascii_chars[pixel_value // 25]
22
+
23
+ # Reshape the ASCII string to match the resized image dimensions
24
+ ascii_image = "\n".join([ascii_image[i:i + img.width] for i in range(0, len(ascii_image), img.width)])
25
+
26
+ return ascii_image
27
+ except Exception as e:
28
+ return f"Error: {e}"
29
+
30
+ iface = gr.Interface(
31
+ fn=generate_ascii_art,
32
+ inputs="image",
33
+ outputs="text",
34
+ title="ASCII Art Generator",
35
+ description="Upload an image, and this app will turn it into ASCII art!",
36
+ live=True
37
+ )
38
+
39
+ iface.launch()
40
+
41
+
42
+
43
+ '''
44
+ import gradio as gr
45
  import subprocess
46
 
47
  def run_command(command):
 
64
  ["echo 'Hello, Gradio!'"]]
65
  )
66
 
67
+ iface.launch(server_name="0.0.0.0", server_port=7860)
68
+ '''