Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import torch
|
| 3 |
-
from
|
| 4 |
-
from PIL import Image, ImageOps
|
| 5 |
|
| 6 |
class ChatbotIconGenerator:
|
| 7 |
def __init__(self):
|
|
@@ -15,25 +15,16 @@ class ChatbotIconGenerator:
|
|
| 15 |
|
| 16 |
# Predefined prompt templates
|
| 17 |
self.PROMPT_TEMPLATES = [
|
| 18 |
-
# Professional/Corporate
|
| 19 |
-
"Professional AI chatbot avatar, minimalist design, sleek geometric shapes, corporate blue and white color palette",
|
| 20 |
-
"Elegant corporate chatbot icon, modern flat design, clean lines, subtle technology motif",
|
| 21 |
-
|
| 22 |
-
# Cute/Friendly
|
| 23 |
"Cute cartoon chatbot mascot, big eyes, friendly smile, pastel colors, kawaii style",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
"Adorable robot character avatar, round shape, soft colors, playful expression",
|
| 25 |
-
|
| 26 |
-
# Sci-Fi/Tech
|
| 27 |
-
"Futuristic AI chatbot icon, glowing circuit patterns, metallic blue and silver, high-tech aesthetic",
|
| 28 |
-
"Cyberpunk chatbot avatar, neon accents, digital glitch effects, modern tech design",
|
| 29 |
-
|
| 30 |
-
# Minimalist
|
| 31 |
"Ultra-minimalist chatbot icon, simple geometric face, monochrome color scheme",
|
| 32 |
-
"
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
"Watercolor style chatbot icon, soft brush strokes, dreamy color blend, artistic interpretation",
|
| 36 |
-
"Sketch-style chatbot avatar, hand-drawn look, pencil texture, artistic rendering"
|
| 37 |
]
|
| 38 |
|
| 39 |
# Rounding options
|
|
@@ -49,11 +40,12 @@ class ChatbotIconGenerator:
|
|
| 49 |
|
| 50 |
def load_image_generator(self):
|
| 51 |
try:
|
| 52 |
-
|
| 53 |
-
|
|
|
|
| 54 |
torch_dtype=torch.float16,
|
| 55 |
-
|
| 56 |
-
|
| 57 |
)
|
| 58 |
return model.to("cpu")
|
| 59 |
except Exception as e:
|
|
@@ -70,7 +62,6 @@ class ChatbotIconGenerator:
|
|
| 70 |
|
| 71 |
# Create a mask for rounded corners
|
| 72 |
mask = Image.new('L', image.size, 255)
|
| 73 |
-
from PIL import ImageDraw
|
| 74 |
draw = ImageDraw.Draw(mask)
|
| 75 |
|
| 76 |
# Draw rounded rectangle
|
|
@@ -89,26 +80,22 @@ class ChatbotIconGenerator:
|
|
| 89 |
prompt,
|
| 90 |
size,
|
| 91 |
corner_rounding,
|
| 92 |
-
negative_prompt="low quality, bad composition, blurry, ugly",
|
| 93 |
-
num_inference_steps=
|
| 94 |
-
guidance_scale=
|
| 95 |
-
strength=0.75
|
| 96 |
):
|
| 97 |
if self.model is None:
|
| 98 |
-
|
| 99 |
|
| 100 |
try:
|
| 101 |
-
# Create a random initial image of specified size
|
| 102 |
-
default_init_image = torch.randn((1, 3, size, size))
|
| 103 |
-
|
| 104 |
# Generate the image
|
| 105 |
generated_image = self.model(
|
| 106 |
prompt=prompt,
|
| 107 |
negative_prompt=negative_prompt,
|
| 108 |
num_inference_steps=num_inference_steps,
|
| 109 |
guidance_scale=guidance_scale,
|
| 110 |
-
|
| 111 |
-
|
| 112 |
).images[0]
|
| 113 |
|
| 114 |
# Resize and round corners
|
|
@@ -120,7 +107,7 @@ class ChatbotIconGenerator:
|
|
| 120 |
|
| 121 |
except Exception as e:
|
| 122 |
print(f"Error generating image: {e}")
|
| 123 |
-
|
| 124 |
|
| 125 |
def create_gradio_interface(self):
|
| 126 |
with gr.Blocks(title="🤖 Chatbot Icon Generator") as demo:
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from diffusers import DiffusionPipeline
|
| 3 |
import torch
|
| 4 |
+
from PIL import Image, ImageDraw
|
|
|
|
| 5 |
|
| 6 |
class ChatbotIconGenerator:
|
| 7 |
def __init__(self):
|
|
|
|
| 15 |
|
| 16 |
# Predefined prompt templates
|
| 17 |
self.PROMPT_TEMPLATES = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
"Cute cartoon chatbot mascot, big eyes, friendly smile, pastel colors, kawaii style",
|
| 19 |
+
"Professional AI chatbot avatar, minimalist design, sleek geometric shapes, corporate blue and white",
|
| 20 |
+
"Futuristic AI chatbot icon, glowing circuit patterns, metallic blue and silver",
|
| 21 |
+
"Abstract geometric chatbot avatar, clean lines, single color gradient background",
|
| 22 |
+
"Watercolor style chatbot icon, soft brush strokes, dreamy color blend",
|
| 23 |
"Adorable robot character avatar, round shape, soft colors, playful expression",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
"Ultra-minimalist chatbot icon, simple geometric face, monochrome color scheme",
|
| 25 |
+
"Cyberpunk chatbot avatar, neon accents, digital glitch effects",
|
| 26 |
+
"Elegant corporate chatbot icon, modern flat design, clean lines",
|
| 27 |
+
"Sketch-style chatbot avatar, hand-drawn look, pencil texture"
|
|
|
|
|
|
|
| 28 |
]
|
| 29 |
|
| 30 |
# Rounding options
|
|
|
|
| 40 |
|
| 41 |
def load_image_generator(self):
|
| 42 |
try:
|
| 43 |
+
# Use a more lightweight model
|
| 44 |
+
model = DiffusionPipeline.from_pretrained(
|
| 45 |
+
"runwayml/stable-diffusion-v1-5", # kopyl/ui-icons-256
|
| 46 |
torch_dtype=torch.float16,
|
| 47 |
+
safety_checker=None, # Disable safety checker to reduce load
|
| 48 |
+
requires_safety_checker=False
|
| 49 |
)
|
| 50 |
return model.to("cpu")
|
| 51 |
except Exception as e:
|
|
|
|
| 62 |
|
| 63 |
# Create a mask for rounded corners
|
| 64 |
mask = Image.new('L', image.size, 255)
|
|
|
|
| 65 |
draw = ImageDraw.Draw(mask)
|
| 66 |
|
| 67 |
# Draw rounded rectangle
|
|
|
|
| 80 |
prompt,
|
| 81 |
size,
|
| 82 |
corner_rounding,
|
| 83 |
+
negative_prompt="low quality, bad composition, blurry, ugly, deformed",
|
| 84 |
+
num_inference_steps=20,
|
| 85 |
+
guidance_scale=7.5
|
|
|
|
| 86 |
):
|
| 87 |
if self.model is None:
|
| 88 |
+
raise ValueError("Model failed to load. Please check your dependencies.")
|
| 89 |
|
| 90 |
try:
|
|
|
|
|
|
|
|
|
|
| 91 |
# Generate the image
|
| 92 |
generated_image = self.model(
|
| 93 |
prompt=prompt,
|
| 94 |
negative_prompt=negative_prompt,
|
| 95 |
num_inference_steps=num_inference_steps,
|
| 96 |
guidance_scale=guidance_scale,
|
| 97 |
+
height=size,
|
| 98 |
+
width=size
|
| 99 |
).images[0]
|
| 100 |
|
| 101 |
# Resize and round corners
|
|
|
|
| 107 |
|
| 108 |
except Exception as e:
|
| 109 |
print(f"Error generating image: {e}")
|
| 110 |
+
raise
|
| 111 |
|
| 112 |
def create_gradio_interface(self):
|
| 113 |
with gr.Blocks(title="🤖 Chatbot Icon Generator") as demo:
|