weijiang2024 commited on
Commit
93928ed
1 Parent(s): 2ddb030

Upload folder using huggingface_hub

Browse files
Files changed (11) hide show
  1. .gitattributes +10 -35
  2. .gitignore +5 -0
  3. README.md +13 -9
  4. SD3_API.ipynb +3 -0
  5. app.py +32 -145
  6. brand.EcoSip.md +43 -0
  7. brand.GreenGlow.Skincare.md +43 -0
  8. brand.LumaWear.md +43 -0
  9. brand.TechGuard.md +43 -0
  10. requirements.txt +4 -4
  11. sd3_api.py +365 -0
.gitattributes CHANGED
@@ -1,35 +1,10 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ #
2
+ # https://help.github.com/articles/dealing-with-line-endings/
3
+ #
4
+ # Linux start script should use lf
5
+ /gradlew text eol=lf
6
+
7
+ # These are Windows script files and should use crlf
8
+ *.bat text eol=crlf
9
+
10
+ SD3_API.ipynb filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Ignore Gradle project-specific cache directory
2
+ .gradle
3
+
4
+ # Ignore Gradle build output directory
5
+ build
README.md CHANGED
@@ -1,15 +1,19 @@
1
  ---
2
  title: Suanfamama_AIGC_alg2
3
- emoji: 🎨
4
- colorFrom: blue
5
- colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 4.36.1
8
  app_file: app.py
9
- pinned: true
10
- license: mit
11
  ---
12
 
13
  # alg 算法
14
- ## How to Deploy to Huggingface Spaces
15
- * gradio deploy
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: Suanfamama_AIGC_alg2
 
 
 
 
 
3
  app_file: app.py
4
+ sdk: gradio
5
+ sdk_version: 4.29.0
6
  ---
7
 
8
  # alg 算法
9
+ ## 基于Stable Diffusion的文生图算法模型调试
10
+ ## How to Deploy
11
+ ```zsh
12
+ gradio deploy
13
+ ```
14
+
15
+ ## 文生图模型 正向关键词 测试列表
16
+ 1. Create an image of a vibrant outdoor scene with a group of diverse, fit individuals engaged in activities like yoga, running, and cycling. They are wearing stylish, eco-friendly activewear with sleek designs and vibrant colors. Include subtle elements of nature like leaves, flowers, or water flowing around the subjects to emphasize the eco-friendly aspect. The scene should evoke a sense of harmony with nature and active lifestyle.
17
+ 2. Create an image of a clean, modern kitchen or office setting with lots of natural light. Show a diverse group of people using eco-friendly, reusable water bottles and travel mugs. Include scenes like a commuter sipping from a travel mug, a jogger hydrating with a water bottle, and an office worker refilling a bottle at a water station. Focus on the sleek design and eco-friendly materials of the bottles and mugs. Incorporate subtle eco-friendly icons or elements like a recycling symbol or green leaves. Use vibrant colors to make the products stand out.
18
+ 3. Create an image of a serene, spa-like setting with natural elements such as plants, wooden textures, and soft lighting. Show a diverse group of individuals with glowing skin using organic, cruelty-free skincare products. Highlight different products like face serums, moisturizers, and cleansers. Focus on the natural ingredients and eco-friendly packaging of the products. Incorporate elements like leaves, flowers, and water to emphasize the organic nature of the products. Use soft, earthy tones to create a calm and inviting atmosphere.
19
+ 4. Create an image of a modern, cozy home setting with smart security devices subtly integrated into the environment. Show a family at home, feeling safe and secure due to the presence of security cameras, smart doorbells, and sensors. Highlight moments like kids playing, parents relaxing, and the devices in action, such as a smartphone showing the security app. Focus on the sleek design of the security devices and their seamless integration into the home. Use warm lighting to create a welcoming and secure atmosphere. Include subtle icons or text indicating advanced features like real-time alerts, HD video, and 24/7 monitoring.
SD3_API.ipynb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8a9240cf84ac5e3bfba4bebc82ded5d0d4e8df7f0d07a1b88780a919e251074f
3
+ size 10791648
app.py CHANGED
@@ -1,150 +1,37 @@
1
- import os
2
  import gradio as gr
3
- import numpy as np
4
- import random
5
  import torch
6
- from diffusers import StableDiffusion3Pipeline, SD3Transformer2DModel, FlowMatchEulerDiscreteScheduler
7
- from huggingface_hub import snapshot_download
8
- import spaces
9
 
10
- huggingface_token = os.getenv("HUGGINGFACE_TOKEN")
 
 
 
 
 
11
 
12
- model_path = snapshot_download(
13
- repo_id="stabilityai/stable-diffusion-3-medium",
14
- revision="refs/pr/26",
15
- repo_type="model",
16
- ignore_patterns=["*.md", "*..gitattributes"],
17
- local_dir="stable-diffusion-3-medium",
18
- token=huggingface_token, # type a new token-id.
19
- )
20
- #repo = "stabilityai/stable-diffusion-3-medium-diffusers"
21
-
22
- device = "cuda" if torch.cuda.is_available() else "cpu"
23
- dtype = torch.float16
24
-
25
- pipe = StableDiffusion3Pipeline.from_pretrained(model_path, torch_dtype=torch.float16).to(device)
26
-
27
- MAX_SEED = np.iinfo(np.int32).max
28
- MAX_IMAGE_SIZE = 1344
29
-
30
- @spaces.GPU
31
- def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
32
-
33
- if randomize_seed:
34
- seed = random.randint(0, MAX_SEED)
35
-
36
- generator = torch.Generator().manual_seed(seed)
37
-
38
  image = pipe(
39
- prompt = prompt,
40
- negative_prompt = negative_prompt,
41
- guidance_scale = guidance_scale,
42
- num_inference_steps = num_inference_steps,
43
- width = width,
44
- height = height,
45
- generator = generator
46
- ).images[0]
47
-
48
- return image, seed
49
-
50
- examples = [
51
- "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
52
- "An astronaut riding a green horse",
53
- "A delicious ceviche cheesecake slice",
54
- ]
55
-
56
- css="""
57
- #col-container {
58
- margin: 0 auto;
59
- max-width: 580px;
60
- }
61
- """
62
-
63
- with gr.Blocks(css=css) as demo:
64
-
65
- with gr.Column(elem_id="col-container"):
66
- gr.Markdown(f"""
67
- # Demo [Stable Diffusion 3 Medium](https://huggingface.co/stabilityai/stable-diffusion-3-medium)
68
- Learn more about the [Stable Diffusion 3 series](https://stability.ai/news/stable-diffusion-3). Try on [Stability AI API](https://platform.stability.ai/docs/api-reference#tag/Generate/paths/~1v2beta~1stable-image~1generate~1sd3/post), [Stable Assistant](https://stability.ai/stable-assistant), or on Discord via [Stable Artisan](https://stability.ai/stable-artisan). Run locally with [ComfyUI](https://github.com/comfyanonymous/ComfyUI) or [diffusers](https://github.com/huggingface/diffusers)
69
- """)
70
-
71
- with gr.Row():
72
-
73
- prompt = gr.Text(
74
- label="Prompt",
75
- show_label=False,
76
- max_lines=1,
77
- placeholder="Enter your prompt",
78
- container=False,
79
- )
80
-
81
- run_button = gr.Button("Run", scale=0)
82
-
83
- result = gr.Image(label="Result", show_label=False)
84
-
85
- with gr.Accordion("Advanced Settings", open=False):
86
-
87
- negative_prompt = gr.Text(
88
- label="Negative prompt",
89
- max_lines=1,
90
- placeholder="Enter a negative prompt",
91
- )
92
-
93
- seed = gr.Slider(
94
- label="Seed",
95
- minimum=0,
96
- maximum=MAX_SEED,
97
- step=1,
98
- value=0,
99
- )
100
-
101
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
102
-
103
- with gr.Row():
104
-
105
- width = gr.Slider(
106
- label="Width",
107
- minimum=256,
108
- maximum=MAX_IMAGE_SIZE,
109
- step=64,
110
- value=1024,
111
- )
112
-
113
- height = gr.Slider(
114
- label="Height",
115
- minimum=256,
116
- maximum=MAX_IMAGE_SIZE,
117
- step=64,
118
- value=1024,
119
- )
120
-
121
- with gr.Row():
122
-
123
- guidance_scale = gr.Slider(
124
- label="Guidance scale",
125
- minimum=0.0,
126
- maximum=10.0,
127
- step=0.1,
128
- value=5.0,
129
- )
130
-
131
- num_inference_steps = gr.Slider(
132
- label="Number of inference steps",
133
- minimum=1,
134
- maximum=50,
135
- step=1,
136
- value=28,
137
- )
138
-
139
- gr.Examples(
140
- examples = examples,
141
- inputs = [prompt]
142
- )
143
- gr.on(
144
- triggers=[run_button.click, prompt.submit, negative_prompt.submit],
145
- fn = infer,
146
- inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
147
- outputs = [result, seed]
148
- )
149
-
150
- demo.launch()
 
 
1
  import gradio as gr
 
 
2
  import torch
3
+ from diffusers import StableDiffusion3Pipeline
 
 
4
 
5
+ # Load the model
6
+ pipe = StableDiffusion3Pipeline.from_pretrained(
7
+ "stable-diffusion-3-medium-diffusers",
8
+ torch_dtype=torch.float16
9
+ )
10
+ pipe = pipe.to("cuda:1")
11
 
12
+ def generate_image(prompt, negative_prompt, num_inference_steps, guidance_scale):
13
+ # Generate the image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  image = pipe(
15
+ prompt,
16
+ negative_prompt=negative_prompt,
17
+ num_inference_steps=num_inference_steps,
18
+ guidance_scale=guidance_scale
19
+ ).images[0]
20
+ return image
21
+
22
+ # Create the Gradio interface
23
+ interface = gr.Interface(
24
+ fn=generate_image,
25
+ inputs=[
26
+ gr.Textbox(label="正向提示词"),
27
+ gr.Textbox(label="负向提示词", placeholder="Optional"),
28
+ gr.Slider(step=1, minimum=1, maximum=100, value=28, label="推理步数"),
29
+ gr.Slider(minimum=1.0, maximum=20.0, step=0.1, value=7.0, label="Guidance Scale")
30
+ ],
31
+ outputs="image",
32
+ title="Stable Diffusion 3 Image Generator",
33
+ description="Generate images with Stable Diffusion 3. Type a prompt and see the magic!"
34
+ )
35
+
36
+ # Launch the interface
37
+ interface.launch(server_name="0.0.0.0", server_port=8912, inbrowser=True, share=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
brand.EcoSip.md ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Brand: EcoSip
2
+
3
+ ## Core Products
4
+ - Eco-friendly, reusable water bottles and travel mugs
5
+
6
+ ## Target Audience:
7
+ - Environmentally conscious consumers
8
+ - Active lifestyle enthusiasts
9
+ - Office workers and commuters
10
+
11
+ ## Image-Based Ad:
12
+ ### Ad Concept:
13
+ - Tagline: "Sip Sustainably. Drink Responsibly."
14
+ ### Visual Description:
15
+ - Background: A clean, modern kitchen or office setting with lots of natural light.
16
+ - Main Subjects: A diverse group of people using EcoSip products in various scenarios (e.g., a commuter sipping from a travel mug, a jogger hydrating with a water bottle, an office worker refilling a bottle at a water station).
17
+ - Product Highlight: Focus on the sleek design and eco-friendly materials of the bottles and mugs. Incorporate subtle eco-friendly icons or elements, like a recycling symbol or green leaves.
18
+ - Additional Elements: Use vibrant colors to make the products stand out and to evoke a sense of freshness and responsibility.
19
+ ### Ad Copy:
20
+ #### Header:
21
+ - "Hydrate Green with EcoSip"
22
+ #### Subheader:
23
+ - "Eco-Friendly Bottles and Mugs for Every Lifestyle"
24
+ #### Body Text:
25
+ "Join the movement towards a sustainable future. Our reusable bottles and mugs are designed to keep you hydrated while reducing plastic waste. Perfect for work, travel, and fitness. Choose EcoSip and make a difference!"
26
+ #### Call to Action (CTA):
27
+ "Shop Now and Get 15% Off Your First Order! 🌍💧"
28
+ #### Footer:
29
+ - Website: www.ecosip.com
30
+ - Social Media Icons: Instagram, Facebook, Twitter (@EcoSipOfficial)
31
+ #### Stable Diffusion/MidJourney Prompt:
32
+ - Create an image of a clean, modern kitchen or office setting with lots of natural light. Show a diverse group of people using eco-friendly, reusable water bottles and travel mugs. Include scenes like a commuter sipping from a travel mug, a jogger hydrating with a water bottle, and an office worker refilling a bottle at a water station. Focus on the sleek design and eco-friendly materials of the bottles and mugs. Incorporate subtle eco-friendly icons or elements like a recycling symbol or green leaves. Use vibrant colors to make the products stand out.
33
+ #### Final Ad Layout:
34
+ ##### Top Section:
35
+ - Header: "Hydrate Green with EcoSip"
36
+ ##### Image Section:
37
+ - The generated image from Stable Diffusion/MidJourney.
38
+ ##### Middle Section:
39
+ - Subheader: "Eco-Friendly Bottles and Mugs for Every Lifestyle"
40
+ - Body Text: "Join the movement towards a sustainable future. Our reusable bottles and mugs are designed to keep you hydrated while reducing plastic waste. Perfect for work, travel, and fitness. Choose EcoSip and make a difference!"
41
+ ##### Bottom Section:
42
+ - CTA: "Shop Now and Get 15% Off Your First Order! 🌍💧"
43
+ - Footer: Website and Social Media Icons
brand.GreenGlow.Skincare.md ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Brand: GreenGlow Skincare
2
+ ## Core Products
3
+ - Organic, cruelty-free skincare products
4
+
5
+ ## Target Audience:
6
+ - Health and beauty enthusiasts
7
+ - Environmentally conscious consumers
8
+ - Individuals seeking natural and organic skincare solutions
9
+
10
+ ## Image-Based Ad:
11
+ ### Ad Concept:
12
+ - Tagline: "Nourish Your Skin Naturally."
13
+ ### Visual Description:
14
+ - Background: A serene, spa-like setting with natural elements such as plants, wooden textures, and soft lighting.
15
+ - Main Subjects: A diverse group of individuals with glowing skin using GreenGlow products. Highlight different products like face serums, moisturizers, and cleansers.
16
+ - Product Highlight: Focus on the natural ingredients and eco-friendly packaging of the products. Incorporate elements like leaves, flowers, and water to emphasize the organic nature of the products.
17
+ - Additional Elements: Use soft, earthy tones to create a calm and inviting atmosphere.
18
+ ### Ad Copy:
19
+ #### Header:
20
+ - "Experience Pure Beauty with GreenGlow"
21
+ #### Subheader:
22
+ - "Organic, Cruelty-Free Skincare for Radiant Results"
23
+ #### Body Text:
24
+ - "Treat your skin to the best nature has to offer. Our organic and cruelty-free skincare products are crafted with pure ingredients to nourish and rejuvenate your skin. Discover the power of GreenGlow for a radiant, healthy complexion."
25
+ #### Call to Action (CTA):
26
+ - "Shop Now and Get 10% Off Your First Order! 🌿✨"
27
+ #### Footer:
28
+ - Website: www.greenglow.com
29
+ - Social Media Icons: Instagram, Facebook, Twitter (@GreenGlowSkincare)
30
+ #### Stable Diffusion/MidJourney Prompt:
31
+ - Create an image of a serene, spa-like setting with natural elements such as plants, wooden textures, and soft lighting. Show a diverse group of individuals with glowing skin using organic, cruelty-free skincare products. Highlight different products like face serums, moisturizers, and cleansers. Focus on the natural ingredients and eco-friendly packaging of the products. Incorporate elements like leaves, flowers, and water to emphasize the organic nature of the products. Use soft, earthy tones to create a calm and inviting atmosphere.
32
+ #### Final Ad Layout:
33
+ ##### Top Section:
34
+ - Header: "Experience Pure Beauty with GreenGlow"
35
+ ##### Image Section:
36
+ - The generated image from Stable Diffusion/MidJourney.
37
+ ##### Middle Section:
38
+ - Subheader: "Organic, Cruelty-Free Skincare for Radiant Results"
39
+ - Body Text: "Treat your skin to the best nature has to offer. Our organic and cruelty-free skincare products are crafted with pure ingredients to nourish and rejuvenate your skin. Discover the power of GreenGlow for a radiant, healthy complexion."
40
+ ##### Bottom Section:
41
+ - CTA: "Shop Now and Get 10% Off Your First Order! 🌿✨"
42
+ - Footer: Website and Social Media Icons
43
+ With this plan, you can use Stable Diffusion or MidJourney to generate the visual, and combine it with the ad copy to create an appealing and effective image-based ad for GreenGlow Skincare.
brand.LumaWear.md ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Brand: LumaWear
2
+
3
+ ## Core Products
4
+ - Innovative, eco-friendly, and stylish activewear
5
+
6
+ ## Target Audience
7
+ - Health-conscious individuals
8
+ - Environmentally aware consumers
9
+ - Fashion-forward fitness enthusiasts
10
+
11
+ ## Image-Based Ad
12
+ ### Ad Concept
13
+ - Tagline: "Move with the Planet. Style with a Purpose."
14
+ ### Visual Description
15
+ - Background: A vibrant outdoor scene, such as a lush green forest or a serene beach at sunset.
16
+ - Main Subjects: Diverse group of fit individuals engaged in various physical activities (yoga, running, cycling) wearing LumaWear activewear.
17
+ - Product Highlight: Focus on the details of the activewear - sleek designs, eco-friendly materials, and vibrant colors.
18
+ - Additional Elements: Subtle elements of nature intertwined with the clothing (e.g., leaves, flowers, or water flowing around the subjects) to emphasize the eco-friendly aspect.
19
+ ### Ad Copy
20
+ #### Header
21
+ - "Embrace Nature, Empower Your Workout"
22
+ #### Subheader
23
+ - "LumaWear - Eco-Friendly Activewear for the Conscious Athlete"
24
+ #### Body Text
25
+ - "Discover the perfect blend of style, performance, and sustainability. Our activewear is crafted from recycled materials, ensuring you move with confidence and care for the planet. Join the LumaWear movement today!"
26
+ #### Call to Action (CTA)
27
+ - "Shop Now and Get 20% Off Your First Purchase! 🌿👟"
28
+ #### Footer
29
+ - Website: www.lumawear.com
30
+ - Social Media Icons: Instagram, Facebook, Twitter (@LumaWearOfficial)
31
+ #### Stable Diffusion/MidJourney Prompt
32
+ - Create an image of a vibrant outdoor scene with a group of diverse, fit individuals engaged in activities like yoga, running, and cycling. They are wearing stylish, eco-friendly activewear with sleek designs and vibrant colors. Include subtle elements of nature like leaves, flowers, or water flowing around the subjects to emphasize the eco-friendly aspect. The scene should evoke a sense of harmony with nature and active lifestyle.
33
+ ### Final Ad Layout:
34
+ #### Top Section:
35
+ - Header: "Embrace Nature, Empower Your Workout"
36
+ #### Image Section:
37
+ - The generated image from Stable Diffusion/MidJourney.
38
+ #### Middle Section:
39
+ - Subheader: "LumaWear - Eco-Friendly Activewear for the Conscious Athlete"
40
+ - Body Text: "Discover the perfect blend of style, performance, and sustainability. Our activewear is crafted from recycled materials, ensuring you move with confidence and care for the planet. Join the LumaWear movement today!"
41
+ #### Bottom Section:
42
+ - CTA: "Shop Now and Get 20% Off Your First Purchase! 🌿👟"
43
+ - Footer: Website and Social Media Icons
brand.TechGuard.md ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Brand: TechGuard
2
+ ## Core Products:
3
+ - Cutting-edge home security systems
4
+
5
+ ## Target Audience:
6
+ - Homeowners
7
+ - Families
8
+ - Tech-savvy individuals
9
+ - Security-conscious consumers
10
+
11
+ ## Image-Based Ad:
12
+ ### Ad Concept:
13
+ - Tagline: "Protect What Matters Most."
14
+ ### Visual Description:
15
+ - Background: A modern, cozy home setting with smart security devices subtly integrated into the environment (e.g., security cameras, smart doorbells, and sensors).
16
+ - Main Subjects: A family at home, feeling safe and secure due to the presence of TechGuard devices. Highlight moments like kids playing, parents relaxing, and the devices in action (e.g., a smartphone showing the security app).
17
+ - Product Highlight: Focus on the sleek design of the security devices and their seamless integration into the home. Emphasize the user-friendly app interface on a smartphone or tablet.
18
+ - Additional Elements: Use warm lighting to create a welcoming and secure atmosphere. Include subtle icons or text indicating advanced features like real-time alerts, HD video, and 24/7 monitoring.
19
+ ### Ad Copy:
20
+ #### Header:
21
+ - "Your Home, Secure with TechGuard"
22
+ #### Subheader:
23
+ - "Advanced Home Security Solutions for Ultimate Peace of Mind"
24
+ #### Body Text:
25
+ - "Ensure the safety of your loved ones with our state-of-the-art home security systems. TechGuard offers real-time alerts, HD video monitoring, and 24/7 protection, all accessible through our easy-to-use app. Trust TechGuard to protect what matters most."
26
+ #### Call to Action (CTA):
27
+ - "Order Now and Get Free Installation! 🏡🔒"
28
+ #### Footer:
29
+ - Website: www.techguard.com
30
+ - Social Media Icons: Instagram, Facebook, Twitter (@TechGuardSecure)
31
+ #### Stable Diffusion/MidJourney Prompt:
32
+ - the above #4 prompt
33
+ ### Final Ad Layout:
34
+ #### Top Section:
35
+ - Header: "Your Home, Secure with TechGuard"
36
+ #### Image Section:
37
+ - The generated image from Stable Diffusion/MidJourney.
38
+ #### Middle Section:
39
+ - Subheader: "Advanced Home Security Solutions for Ultimate Peace of Mind"
40
+ - Body Text: "Ensure the safety of your loved ones with our state-of-the-art home security systems. TechGuard offers real-time alerts, HD video monitoring, and 24/7 protection, all accessible through our easy-to-use app. Trust TechGuard to protect what matters most."
41
+ #### Bottom Section:
42
+ - CTA: "Order Now and Get Free Installation! 🏡🔒"
43
+ - Footer: Website and Social Media Icons
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- git+https://github.com/huggingface/diffusers.git
2
- transformers
3
- accelerate
4
- sentencepiece
 
1
+ gradio
2
+ torch
3
+ diffusers
4
+ transformers
sd3_api.py ADDED
@@ -0,0 +1,365 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """SD3_API.ipynb
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/github/stability-ai/stability-sdk/blob/main/nbs/SD3_API.ipynb
8
+
9
+ # SD3 and SD3-Turbo
10
+
11
+ Welcome. This notebook can be used to try out the SD3 service from Stability.
12
+
13
+
14
+ ---
15
+
16
+
17
+
18
+ New to colab? Just hit the play button on each of the cells and follow instructions.
19
+
20
+ You will need an account on https://platform.stability.ai/ to use the features.
21
+
22
+ Have fun and do great things.
23
+ """
24
+
25
+ #@title Install requirements
26
+ from io import BytesIO
27
+ import IPython
28
+ import json
29
+ import os
30
+ from PIL import Image
31
+ import requests
32
+ import time
33
+ from google.colab import output
34
+
35
+ #@title Connect to the Stability API
36
+
37
+ import getpass
38
+ # @markdown To get your API key visit https://platform.stability.ai/account/keys
39
+ STABILITY_KEY = getpass.getpass('Enter your API Key')
40
+
41
+ #@title Define functions
42
+
43
+ def send_generation_request(
44
+ host,
45
+ params,
46
+ ):
47
+ headers = {
48
+ "Accept": "image/*",
49
+ "Authorization": f"Bearer {STABILITY_KEY}"
50
+ }
51
+
52
+ # Encode parameters
53
+ files = {}
54
+ image = params.pop("image", None)
55
+ mask = params.pop("mask", None)
56
+ if image is not None and image != '':
57
+ files["image"] = open(image, 'rb')
58
+ if mask is not None and mask != '':
59
+ files["mask"] = open(mask, 'rb')
60
+ if len(files)==0:
61
+ files["none"] = ''
62
+
63
+ # Send request
64
+ print(f"Sending REST request to {host}...")
65
+ response = requests.post(
66
+ host,
67
+ headers=headers,
68
+ files=files,
69
+ data=params
70
+ )
71
+ if not response.ok:
72
+ raise Exception(f"HTTP {response.status_code}: {response.text}")
73
+
74
+ return response
75
+
76
+ """# Generate
77
+
78
+ Stable Image services include one offering currently in production:
79
+
80
+ - SD3 Large: The 2 billion parameter model. This service will use 6.5 credits.
81
+ - SD3 Large Turbo: The 8 billion parameter model. This service will use 4 credits.
82
+ - SD3 Medium: The 8 billion parameter model with a faster inference time. This service will use 3.5 credits.
83
+
84
+ See https://platform.stability.ai/docs/api-reference#tag/Generate
85
+
86
+ Try these services out in the sections below. Check back in for regular updates.
87
+
88
+ Feedback welcome.
89
+
90
+ # Text to Image
91
+ """
92
+
93
+ #@title SD3 Large
94
+
95
+ prompt = "This dreamlike digital art captures a vibrant, kaleidoscopic bird in a lush rainforest" #@param {type:"string"}
96
+ negative_prompt = "" #@param {type:"string"}
97
+ aspect_ratio = "1:1" #@param ["21:9", "16:9", "3:2", "5:4", "1:1", "4:5", "2:3", "9:16", "9:21"]
98
+ seed = 0 #@param {type:"integer"}
99
+ output_format = "jpeg" #@param ["jpeg", "png"]
100
+
101
+ host = f"https://api.stability.ai/v2beta/stable-image/generate/sd3"
102
+
103
+ params = {
104
+ "prompt" : prompt,
105
+ "negative_prompt" : negative_prompt,
106
+ "aspect_ratio" : aspect_ratio,
107
+ "seed" : seed,
108
+ "output_format" : output_format,
109
+ "model" : "sd3-large",
110
+ "mode" : "text-to-image"
111
+ }
112
+
113
+ response = send_generation_request(
114
+ host,
115
+ params
116
+ )
117
+
118
+ # Decode response
119
+ output_image = response.content
120
+ finish_reason = response.headers.get("finish-reason")
121
+ seed = response.headers.get("seed")
122
+
123
+ # Check for NSFW classification
124
+ if finish_reason == 'CONTENT_FILTERED':
125
+ raise Warning("Generation failed NSFW classifier")
126
+
127
+ # Save and display result
128
+ generated = f"generated_{seed}.{output_format}"
129
+ with open(generated, "wb") as f:
130
+ f.write(output_image)
131
+ print(f"Saved image {generated}")
132
+
133
+ output.no_vertical_scroll()
134
+ print("Result image:")
135
+ IPython.display.display(Image.open(generated))
136
+
137
+ #@title SD3 Large Turbo
138
+
139
+ prompt = "A car made out of vegetables." #@param {type:"string"}
140
+ aspect_ratio = "1:1" #@param ["21:9", "16:9", "3:2", "5:4", "1:1", "4:5", "2:3", "9:16", "9:21"]
141
+ seed = 0 #@param {type:"integer"}
142
+ output_format = "jpeg" #@param ["jpeg", "png"]
143
+
144
+ host = f"https://api.stability.ai/v2beta/stable-image/generate/sd3"
145
+
146
+ params = {
147
+ "prompt" : prompt,
148
+ "aspect_ratio" : aspect_ratio,
149
+ "seed" : seed,
150
+ "output_format" : output_format,
151
+ "model" : "sd3-large-turbo"
152
+ }
153
+
154
+ response = send_generation_request(
155
+ host,
156
+ params
157
+ )
158
+
159
+ # Decode response
160
+ output_image = response.content
161
+ finish_reason = response.headers.get("finish-reason")
162
+ seed = response.headers.get("seed")
163
+
164
+ # Check for NSFW classification
165
+ if finish_reason == 'CONTENT_FILTERED':
166
+ raise Warning("Generation failed NSFW classifier")
167
+
168
+ # Save and display result
169
+ generated = f"generated_{seed}.{output_format}"
170
+ with open(generated, "wb") as f:
171
+ f.write(output_image)
172
+ print(f"Saved image {generated}")
173
+
174
+ output.no_vertical_scroll()
175
+ print("Result image:")
176
+ IPython.display.display(Image.open(generated))
177
+
178
+ #@title SD3 Medium
179
+
180
+ prompt = "glowing mushroom in the alchemist's garden" #@param {type:"string"}
181
+ aspect_ratio = "1:1" #@param ["21:9", "16:9", "3:2", "5:4", "1:1", "4:5", "2:3", "9:16", "9:21"]
182
+ seed = 0 #@param {type:"integer"}
183
+ output_format = "jpeg" #@param ["jpeg", "png"]
184
+
185
+ host = f"https://api.stability.ai/v2beta/stable-image/generate/sd3"
186
+
187
+ params = {
188
+ "prompt" : prompt,
189
+ "aspect_ratio" : aspect_ratio,
190
+ "seed" : seed,
191
+ "output_format" : output_format,
192
+ "model" : "sd3-medium"
193
+ }
194
+
195
+ response = send_generation_request(
196
+ host,
197
+ params
198
+ )
199
+
200
+ # Decode response
201
+ output_image = response.content
202
+ finish_reason = response.headers.get("finish-reason")
203
+ seed = response.headers.get("seed")
204
+
205
+ # Check for NSFW classification
206
+ if finish_reason == 'CONTENT_FILTERED':
207
+ raise Warning("Generation failed NSFW classifier")
208
+
209
+ # Save and display result
210
+ generated = f"generated_{seed}.{output_format}"
211
+ with open(generated, "wb") as f:
212
+ f.write(output_image)
213
+ print(f"Saved image {generated}")
214
+
215
+ output.no_vertical_scroll()
216
+ print("Result image:")
217
+ IPython.display.display(Image.open(generated))
218
+
219
+ """# Image to Image"""
220
+
221
+ #@title SD3 Large
222
+ #@markdown - Drag and drop image to file folder on left
223
+ #@markdown - Right click it and choose Copy path
224
+ #@markdown - Paste that path into image field below
225
+ #@markdown <br><br>
226
+
227
+ image = "/content/veggiecar.png" #@param {type:"string"}
228
+ prompt = "A car made out of fruits" #@param {type:"string"}
229
+ negative_prompt = "" #@param {type:"string"}
230
+ seed = 0 #@param {type:"integer"}
231
+ output_format = "jpeg" #@param ["jpeg", "png"]
232
+ strength = 0.75 #@param {type:"slider", min:0.0, max: 1.0, step: 0.01}
233
+
234
+ host = f"https://api.stability.ai/v2beta/stable-image/generate/sd3"
235
+
236
+ params = {
237
+ "image" : image,
238
+ "prompt" : prompt,
239
+ "negative_prompt" : negative_prompt,
240
+ "strength" : strength,
241
+ "seed" : seed,
242
+ "output_format": output_format,
243
+ "model" : "sd3-large",
244
+ "mode" : "image-to-image"
245
+ }
246
+
247
+ response = send_generation_request(
248
+ host,
249
+ params
250
+ )
251
+
252
+ # Decode response
253
+ output_image = response.content
254
+ finish_reason = response.headers.get("finish-reason")
255
+ seed = response.headers.get("seed")
256
+
257
+ # Check for NSFW classification
258
+ if finish_reason == 'CONTENT_FILTERED':
259
+ raise Warning("Generation failed NSFW classifier")
260
+
261
+ # Save and display result
262
+ generated = f"generated_{seed}.{output_format}"
263
+ with open(generated, "wb") as f:
264
+ f.write(output_image)
265
+ print(f"Saved image {generated}")
266
+
267
+ output.no_vertical_scroll()
268
+ print("Result image:")
269
+ IPython.display.display(Image.open(generated))
270
+
271
+ #@title SD3 Large Turbo
272
+ #@markdown - Drag and drop image to file folder on left
273
+ #@markdown - Right click it and choose Copy path
274
+ #@markdown - Paste that path into image field below
275
+ #@markdown <br><br>
276
+
277
+ image = "/content/veggiecar.png" #@param {type:"string"}
278
+ prompt = "A car made out of flowers" #@param {type:"string"}
279
+ seed = 0 #@param {type:"integer"}
280
+ output_format = "jpeg" #@param ["jpeg", "png"]
281
+ strength = 0.75 #@param {type:"slider", min:0.0, max: 1.0, step: 0.01}
282
+
283
+ host = f"https://api.stability.ai/v2beta/stable-image/generate/sd3"
284
+
285
+ params = {
286
+ "image" : image,
287
+ "prompt" : prompt,
288
+ "strength" : strength,
289
+ "seed" : seed,
290
+ "output_format": output_format,
291
+ "mode" : "image-to-image",
292
+ "model" : "sd3-large-turbo"
293
+ }
294
+
295
+ response = send_generation_request(
296
+ host,
297
+ params
298
+ )
299
+
300
+ # Decode response
301
+ output_image = response.content
302
+ finish_reason = response.headers.get("finish-reason")
303
+ seed = response.headers.get("seed")
304
+
305
+ # Check for NSFW classification
306
+ if finish_reason == 'CONTENT_FILTERED':
307
+ raise Warning("Generation failed NSFW classifier")
308
+
309
+ # Save and display result
310
+ generated = f"generated_{seed}.{output_format}"
311
+ with open(generated, "wb") as f:
312
+ f.write(output_image)
313
+ print(f"Saved image {generated}")
314
+
315
+ output.no_vertical_scroll()
316
+ print("Result image:")
317
+ IPython.display.display(Image.open(generated))
318
+
319
+ #@title SD3 Medium
320
+ #@markdown - Drag and drop image to file folder on left
321
+ #@markdown - Right click it and choose Copy path
322
+ #@markdown - Paste that path into image field below
323
+ #@markdown <br><br>
324
+
325
+ image = "/content/veggiecar.png" #@param {type:"string"}
326
+ prompt = "A car made out of mushrooms" #@param {type:"string"}
327
+ seed = 0 #@param {type:"integer"}
328
+ output_format = "jpeg" #@param ["jpeg", "png"]
329
+ strength = 0.75 #@param {type:"slider", min:0.0, max: 1.0, step: 0.01}
330
+
331
+ host = f"https://api.stability.ai/v2beta/stable-image/generate/sd3"
332
+
333
+ params = {
334
+ "image" : image,
335
+ "prompt" : prompt,
336
+ "strength" : strength,
337
+ "seed" : seed,
338
+ "output_format": output_format,
339
+ "mode" : "image-to-image",
340
+ "model" : "sd3-medium"
341
+ }
342
+
343
+ response = send_generation_request(
344
+ host,
345
+ params
346
+ )
347
+
348
+ # Decode response
349
+ output_image = response.content
350
+ finish_reason = response.headers.get("finish-reason")
351
+ seed = response.headers.get("seed")
352
+
353
+ # Check for NSFW classification
354
+ if finish_reason == 'CONTENT_FILTERED':
355
+ raise Warning("Generation failed NSFW classifier")
356
+
357
+ # Save and display result
358
+ generated = f"generated_{seed}.{output_format}"
359
+ with open(generated, "wb") as f:
360
+ f.write(output_image)
361
+ print(f"Saved image {generated}")
362
+
363
+ output.no_vertical_scroll()
364
+ print("Result image:")
365
+ IPython.display.display(Image.open(generated))