farazify commited on
Commit
59c2540
·
verified ·
1 Parent(s): e886aaa

Update logoGenertor.py

Browse files
Files changed (1) hide show
  1. logoGenertor.py +72 -34
logoGenertor.py CHANGED
@@ -1,34 +1,72 @@
1
- import torch
2
- from diffusers import StableDiffusionPipeline
3
- from PIL import Image
4
- import gradio as gr
5
-
6
- # Load the pre-trained Stable Diffusion model
7
- pipe = StableDiffusionPipeline.from_pretrained(
8
- "runwayml/stable-diffusion-v1-5",
9
- torch_dtype=torch.float16
10
- )
11
- pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
12
-
13
- # Logo generation function
14
- def generate_logo(description):
15
- prompt = f"A high-quality, professional logo: {description}, sharp, modern, HD"
16
- image = pipe(
17
- prompt,
18
- height=512,
19
- width=512,
20
- num_inference_steps=50,
21
- guidance_scale=7.5
22
- ).images[0]
23
- return image.resize((1024, 1024), resample=Image.LANCZOS)
24
-
25
- # Gradio interface
26
- iface = gr.Interface(
27
- fn=generate_logo,
28
- inputs=gr.Textbox(label="Logo Description"),
29
- outputs=gr.Image(type="pil", label="Generated Logo"),
30
- title="AI Logo Generator",
31
- description="Enter a description to generate a high-quality logo"
32
- )
33
-
34
- iface.launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import StableDiffusionPipeline
3
+ import gradio as gr
4
+ import numpy as np
5
+ from PIL import Image
6
+
7
+ # Load model
8
+ pipe = StableDiffusionPipeline.from_pretrained(
9
+ "stabilityai/stable-diffusion-2",
10
+ torch_dtype=torch.float16,
11
+ revision="fp16"
12
+ ).to("cuda" if torch.cuda.is_available() else "cpu")
13
+
14
+ # Style mapping
15
+ STYLE_PRESETS = {
16
+ "Minimal": "minimal flat logo, vector style",
17
+ "Modern": "modern logo, professional design",
18
+ "Retro": "vintage retro logo, 90s style",
19
+ "Tech": "technology startup logo, digital design",
20
+ "Luxury": "luxury brand logo, elegant and premium"
21
+ }
22
+
23
+ # Convert to transparent PNG if background is white-ish
24
+ def remove_white_background(pil_image):
25
+ image = pil_image.convert("RGBA")
26
+ data = np.array(image)
27
+ r, g, b, a = data.T
28
+
29
+ white_areas = (r > 240) & (g > 240) & (b > 240)
30
+ data[..., :-1][white_areas.T] = (255, 255, 255)
31
+ data[..., -1][white_areas.T] = 0 # transparent
32
+ return Image.fromarray(data)
33
+
34
+ # Generate image
35
+ def generate_logo(prompt, style, resolution, transparent):
36
+ if not prompt:
37
+ return None
38
+ styled_prompt = f"{prompt}, {STYLE_PRESETS[style]}"
39
+ width, height = map(int, resolution.split('x'))
40
+ image = pipe(styled_prompt, height=height, width=width).images[0]
41
+
42
+ if transparent:
43
+ image = remove_white_background(image)
44
+
45
+ return image
46
+
47
+ # Build UI
48
+ def create_ui():
49
+ with gr.Blocks(theme=gr.themes.Soft(), css=".dark-mode body { background-color: #1e1e1e; color: white; }") as demo:
50
+ gr.Markdown("# 🎨 AI Logo Generator")
51
+ gr.Markdown("Enter a description to generate a high-quality logo")
52
+
53
+ with gr.Row():
54
+ prompt = gr.Textbox(label="Logo Description", placeholder="e.g., A minimalist owl logo for a tech startup")
55
+ style = gr.Dropdown(choices=list(STYLE_PRESETS.keys()), label="Style", value="Minimal")
56
+ resolution = gr.Dropdown(choices=["512x512", "768x768"], label="Resolution", value="512x512")
57
+
58
+ with gr.Row():
59
+ transparent = gr.Checkbox(label="Make background transparent", value=True)
60
+ dark_mode = gr.Checkbox(label="Dark Mode UI", value=False)
61
+ share_space = gr.Checkbox(label="Make app public (Gradio share link)", value=False)
62
+
63
+ output = gr.Image(label="Generated Logo", show_download_button=True, type="pil")
64
+ submit = gr.Button("Generate")
65
+
66
+ submit.click(fn=generate_logo, inputs=[prompt, style, resolution, transparent], outputs=output)
67
+
68
+ return demo
69
+
70
+ if __name__ == "__main__":
71
+ ui = create_ui()
72
+ ui.launch(share=True)