acecalisto3 commited on
Commit
486f82b
·
verified ·
1 Parent(s): fbeadb6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -5,7 +5,8 @@ from PIL import Image
5
  from io import BytesIO
6
  from tqdm import tqdm
7
  import time
8
- import cairosvg
 
9
 
10
  # Defining the repository information and the trigger word
11
  repo = "artificialguybr/LineAniRedmond-LinearMangaSDXL-V2"
@@ -52,9 +53,19 @@ def generate_image(prompt):
52
  print("API response status code:", response.status_code)
53
  if response.status_code == 200:
54
  print("Image generation successful!")
55
- # Convert the response content to an SVG with only black values
56
- image = Image.open(BytesIO(response.content)).convert("L") # Convert to grayscale
57
- svg_data = cairosvg.svg2svg(bytestring=image.tobytes(), output_width=image.width, output_height=image.height)
 
 
 
 
 
 
 
 
 
 
58
  return svg_data
59
  elif response.status_code == 503:
60
  time.sleep(1)
@@ -69,7 +80,7 @@ def generate_image(prompt):
69
  iface = gr.Interface(
70
  fn=generate_image,
71
  inputs=gr.Textbox(lines=2, placeholder="Describe the subject here..."),
72
- outputs="text", # Changed output to text for SVG data
73
  title="LineArt XL Image Generator",
74
  description=(
75
  "Powered by the generous GPU time from Redmond.AI, this LORA, fine-tuned on SD XL 1.0, excels at creating Lineart-themed images across a wide range of subjects. "
@@ -85,4 +96,4 @@ iface = gr.Interface(
85
  )
86
 
87
  print("Launching Gradio interface...")
88
- iface.launch()
 
5
  from io import BytesIO
6
  from tqdm import tqdm
7
  import time
8
+ import numpy as np
9
+ import potrace
10
 
11
  # Defining the repository information and the trigger word
12
  repo = "artificialguybr/LineAniRedmond-LinearMangaSDXL-V2"
 
53
  print("API response status code:", response.status_code)
54
  if response.status_code == 200:
55
  print("Image generation successful!")
56
+ # Open the image and convert it to grayscale
57
+ image = Image.open(BytesIO(response.content)).convert("L")
58
+ # Convert the grayscale image to a binary image
59
+ image = image.point(lambda p: 255 if p > 128 else 0, mode='1')
60
+ # Convert the PIL image to a numpy array
61
+ array = np.array(image)
62
+ # Invert the array for potrace (black on white)
63
+ array = 255 - array
64
+ # Trace the bitmap to SVG
65
+ bitmap = potrace.Bitmap(array)
66
+ path = bitmap.trace()
67
+ # Generate SVG data
68
+ svg_data = path.to_svg()
69
  return svg_data
70
  elif response.status_code == 503:
71
  time.sleep(1)
 
80
  iface = gr.Interface(
81
  fn=generate_image,
82
  inputs=gr.Textbox(lines=2, placeholder="Describe the subject here..."),
83
+ outputs="text", # SVG data as text
84
  title="LineArt XL Image Generator",
85
  description=(
86
  "Powered by the generous GPU time from Redmond.AI, this LORA, fine-tuned on SD XL 1.0, excels at creating Lineart-themed images across a wide range of subjects. "
 
96
  )
97
 
98
  print("Launching Gradio interface...")
99
+ iface.launch()