Jarrodbarnes commited on
Commit
16b902a
1 Parent(s): 85a62a6

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +52 -7
  2. SD3.py +53 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,12 +1,57 @@
1
  ---
2
- title: Stable Diffusion 3
3
- emoji: 🏃
4
- colorFrom: gray
5
- colorTo: red
6
  sdk: gradio
7
  sdk_version: 4.26.0
8
- app_file: app.py
9
- pinned: false
10
  ---
 
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: stable-diffusion-3
3
+ app_file: SD3.py
 
 
4
  sdk: gradio
5
  sdk_version: 4.26.0
 
 
6
  ---
7
+ # Stable Diffusion 3 Text-to-Image Generator
8
 
9
+ This is a Python application that utilizes the Stable Diffusion 3 model to generate images from textual prompts. It provides a user-friendly interface built with Gradio, allowing users to enter a prompt, select a model, and choose an aspect ratio to generate an image.
10
+
11
+ ## Requirements
12
+
13
+ To run this application, you need to have the following dependencies installed:
14
+
15
+ - requests
16
+ - requests-toolbelt
17
+ - gradio
18
+
19
+ You can install these dependencies by running the following command:
20
+
21
+ ```bash
22
+ pip install -r requirements.txt
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ 1. Clone this repository to your local machine.
28
+ 2. Install the required dependencies using the command mentioned above.
29
+ 3. Replace the `api_key` variable in the `SD3.py` file with your actual Stability AI API key.
30
+ 4. Run the `SD3.py` script using the following command:
31
+
32
+ ```bash
33
+ python SD3.py
34
+ ```
35
+
36
+ 5. The application will launch in your default web browser.
37
+ 6. Enter a text prompt describing the image you want to generate.
38
+ 7. Select the desired model (either "sd3" or "sd3-turbo").
39
+ 8. Choose the aspect ratio for the generated image.
40
+ 9. Click the "Submit" button to generate the image.
41
+ 10. The generated image will be displayed on the screen.
42
+
43
+ ## About Stable Diffusion 3
44
+
45
+ Stable Diffusion 3 is a state-of-the-art text-to-image generation model developed by Stability AI. It is capable of generating high-quality images from textual descriptions, allowing users to create visual content based on their imagination.
46
+
47
+ The model has been trained on a vast dataset of image-text pairs, enabling it to understand and generate images across a wide range of domains and styles. It uses a diffusion-based approach to iteratively refine the generated image, resulting in highly detailed and coherent visual outputs.
48
+
49
+ Stable Diffusion 3 offers two variants: "sd3" and "sd3-turbo". The "sd3" model is the standard version, while "sd3-turbo" is a more powerful and computationally intensive variant that can generate even higher-quality images.
50
+
51
+ ## Acknowledgements
52
+
53
+ This application is built using the Stability AI API and the Gradio library. We would like to thank the developers and contributors of these projects for their excellent work.
54
+
55
+ ## License
56
+
57
+ This project is licensed under the [MIT License](LICENSE).
SD3.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from requests_toolbelt.multipart.encoder import MultipartEncoder
3
+ import gradio as gr
4
+
5
+ def generate_image(prompt, aspect_ratio='1:1', model='sd3', seed=0, output_format='png'):
6
+ api_url = "https://api.stability.ai/v2beta/stable-image/generate/sd3"
7
+ api_key = "sk-lr4V2rv0uFv2dmgD34TPrURw9ppaFgcZs67rNW7zKqJqiHEb" # Replace this with your actual API key
8
+
9
+ m = MultipartEncoder(
10
+ fields={
11
+ 'prompt': prompt,
12
+ 'aspect_ratio': aspect_ratio,
13
+ 'model': model,
14
+ 'seed': str(seed),
15
+ 'output_format': output_format,
16
+ 'mode': 'text-to-image' # Default mode
17
+ }
18
+ )
19
+
20
+ headers = {
21
+ 'Authorization': f'Bearer {api_key}',
22
+ 'Content-Type': m.content_type,
23
+ 'Accept': 'image/*' # To receive the image directly
24
+ }
25
+
26
+ response = requests.post(api_url, data=m, headers=headers)
27
+ print(response.status_code, response.content)
28
+
29
+ if response.status_code == 200:
30
+ # Assuming the response content is the image in binary format
31
+ output_path = 'generated_image.png'
32
+ with open(output_path, 'wb') as f:
33
+ f.write(response.content)
34
+ return output_path # Return the path for Gradio to display the image
35
+ else:
36
+ return f"Error: {response.text}"
37
+
38
+ def wrap_generate_image(prompt, model, aspect_ratio):
39
+ return generate_image(prompt, aspect_ratio, model)
40
+
41
+ iface = gr.Interface(
42
+ fn=wrap_generate_image,
43
+ inputs=[
44
+ gr.Textbox(lines=2, label="Prompt", placeholder="Enter a description for the image..."),
45
+ gr.Radio(choices=['sd3', 'sd3-turbo'], label="Model", value='sd3'),
46
+ gr.Dropdown(choices=['1:1', '16:9', '21:9', '2:3', '3:2', '4:5', '5:4', '9:16', '9:21'], label="Aspect Ratio", value='1:1')
47
+ ],
48
+ outputs=gr.Image(),
49
+ title="Stable Diffusion 3 Text-to-Image Generator",
50
+ description="Select a model, aspect ratio, and enter a prompt to generate an image using Stable Diffusion 3."
51
+ )
52
+
53
+ iface.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ requests
2
+ requests-toolbelt
3
+ gradio