Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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
|
|
|
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 |
-
#
|
56 |
-
image = Image.open(BytesIO(response.content)).convert("L")
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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", #
|
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()
|