Enzo8930302 commited on
Commit
4bd664b
Β·
verified Β·
1 Parent(s): 35a7998

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +100 -240
README.md CHANGED
@@ -1,308 +1,158 @@
1
- # Byte Dream - AI Image Generation Model
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  ## Overview
4
- Byte Dream is a robust, production-ready text-to-image diffusion model optimized for CPU inference. This model uses advanced latent diffusion architecture to generate high-quality images from text prompts. Fully integrated with Hugging Face Hub for easy model sharing, deployment, and cloud API access.
 
5
 
6
  ## Features
7
- - **CPU Optimized**: Runs efficiently on CPU without GPU requirement
8
- - **High Quality**: Generates 512x512 and higher resolution images
9
- - **Fast Inference**: Optimized for speed with quality preservation
10
- - **Hugging Face Native**: Full integration with HF Hub (upload, download, deploy)
11
- - **Cloud API Support**: Use Hugging Face Inference API for cloud-based generation
12
- - **Spaces Ready**: One-click deployment to Hugging Face Spaces
13
- - **Flexible**: Supports various sampling methods and customization
14
- - **Production Ready**: Error handling, memory optimization, batch processing
15
 
16
  ## Installation
17
 
18
- ### Using pip
19
  ```bash
20
- pip install -r requirements.txt
21
- ```
22
-
23
- ### Using conda
24
- ```bash
25
- conda env create -f environment.yml
26
- conda activate bytedream
27
  ```
28
 
29
  ## Usage
30
 
31
- ### Basic Image Generation
32
  ```python
33
  from bytedream import ByteDreamGenerator
34
 
35
- # Initialize generator
36
- generator = ByteDreamGenerator()
37
 
38
- # Generate image from prompt
39
  image = generator.generate(
40
  prompt="A beautiful sunset over mountains, digital art",
41
  num_inference_steps=50,
42
- guidance_scale=7.5
43
  )
44
-
45
- # Save image
46
  image.save("output.png")
47
  ```
48
 
49
- ### Advanced Usage
50
- ```python
51
- from bytedream import ByteDreamGenerator
52
-
53
- generator = ByteDreamGenerator(model_path="models/bytedream")
54
-
55
- # Generate with custom parameters
56
- image = generator.generate(
57
- prompt="Cyberpunk city at night, neon lights, futuristic",
58
- negative_prompt="blurry, low quality, distorted",
59
- width=768,
60
- height=768,
61
- num_inference_steps=100,
62
- guidance_scale=9.0,
63
- seed=42
64
- )
65
-
66
- image.save("cyberpunk_city.png")
67
- ```
68
-
69
- ### Load Model from Hugging Face Hub
70
  ```python
71
- from bytedream import ByteDreamGenerator
72
-
73
- # Load directly from Hugging Face
74
- generator = ByteDreamGenerator(hf_repo_id="username/ByteDream")
75
-
76
- # Generate image
77
- image = generator.generate(
78
- prompt="A majestic dragon, fantasy art, dramatic lighting",
79
- num_inference_steps=50,
80
- guidance_scale=7.5
81
- )
82
-
83
- image.save("dragon.png")
84
- ```
85
-
86
- ### Using Pipeline Directly
87
- ```python
88
- from bytedream.pipeline import ByteDreamPipeline
89
 
90
- # Load pretrained pipeline
91
- pipeline = ByteDreamPipeline.from_pretrained(
92
- "username/ByteDream",
93
- device="cpu",
94
- dtype=torch.float32
95
  )
96
 
97
- # Generate image
98
- result = pipeline(
99
- prompt="A peaceful landscape, cottage, sunny day",
100
- num_inference_steps=50,
101
- guidance_scale=7.5,
102
- height=512,
103
- width=512
104
  )
105
-
106
- result[0].save("landscape.png")
107
- ```
108
-
109
- ### Command Line Interface
110
- ```bash
111
- # Basic usage
112
- python infer.py --prompt "A dragon flying over castle" --output dragon.png
113
-
114
- # With advanced options
115
- python infer.py --prompt "Fantasy landscape" --negative "ugly, blurry" --steps 75 --guidance 8.0
116
-
117
- # Load from Hugging Face
118
- python infer.py --prompt "Cyberpunk city" --hf_repo "username/ByteDream" --output city.png
119
- ```
120
-
121
- ### Gradio Web Interface
122
- ```bash
123
- # Run with local model
124
- python app.py
125
-
126
- # Run with model from Hugging Face
127
- HF_REPO_ID=username/ByteDream python app.py
128
  ```
129
 
130
- ## Model Architecture
131
-
132
- Byte Dream uses a latent diffusion model with:
133
- - **Text Encoder**: CLIP-based text understanding
134
- - **UNet**: Noise prediction network with cross-attention
135
- - **VAE**: Variational Autoencoder for image compression
136
- - **Scheduler**: Advanced DDIM/PNDM sampling
137
-
138
  ## Training
139
 
140
- ### Prepare Dataset
141
- ```bash
142
- python prepare_dataset.py --data_dir ./dataset --output_dir ./processed_data
143
- ```
144
-
145
- ### Train Model
146
- ```bash
147
- python train.py \
148
- --train_data ./processed_data \
149
- --output_dir ./models/bytedream \
150
- --epochs 100 \
151
- --batch_size 4 \
152
- --learning_rate 1e-5
153
- ```
154
-
155
- ## Hugging Face Deployment
156
-
157
- ### Upload Your Trained Model to Hugging Face Hub
158
-
159
- First, get your Hugging Face token from: https://huggingface.co/settings/tokens
160
 
161
  ```bash
162
- # Method 1: Using publish_to_hf.py (recommended)
163
- python publish_to_hf.py
164
-
165
- # You'll be prompted for:
166
- # - Your HF token
167
- # - Repository ID (e.g., username/ByteDream)
168
-
169
- # Method 2: Using upload_to_hf.py
170
- python upload_to_hf.py \
171
- --model_path ./models/bytedream \
172
- --repo_id username/ByteDream \
173
- --token YOUR_HF_TOKEN
174
-
175
- # Method 3: Programmatically from Python
176
- from bytedream import ByteDreamGenerator
177
-
178
- # Train your model first
179
- generator = ByteDreamGenerator(model_path="./models/bytedream")
180
 
181
- # Push to Hub
182
- generator.push_to_hub(
183
- repo_id="username/ByteDream",
184
- token="YOUR_HF_TOKEN",
185
- private=False
186
- )
187
  ```
188
 
189
- ### Download Model from Hugging Face Hub
190
-
191
- ```python
192
- from bytedream import ByteDreamGenerator
193
-
194
- # Load directly from HF Hub
195
- generator = ByteDreamGenerator(hf_repo_id="username/ByteDream")
196
-
197
- # Or using pipeline
198
- from bytedream.pipeline import ByteDreamPipeline
199
- pipeline = ByteDreamPipeline.from_pretrained("username/ByteDream")
200
- ```
201
 
202
- ### Deploy to Hugging Face Spaces
203
 
204
- #### Option 1: Automatic Deployment (Recommended)
205
  ```bash
206
- python deploy_to_spaces.py --repo_id your_username/ByteDream-Space
207
  ```
208
 
209
- #### Option 2: Manual Deployment
210
- 1. **Create a new Space**: Go to https://huggingface.co/spaces and click "Create new Space"
211
- 2. **Choose Gradio SDK**: Select Gradio as the SDK
212
- 3. **Upload files**: Push all your files to the repository
213
- 4. **Set environment variable** (optional): In your Space settings, set `HF_REPO_ID=username/ByteDream`
214
- 5. **Deploy**: The app will automatically deploy with CPU hardware
215
-
216
- Your Gradio app will be available at: `https://huggingface.co/spaces/your_username/ByteDream-Space`
217
-
218
- ## Hugging Face API Integration
219
 
220
- ### Use Cloud Inference API
221
-
222
- Generate images using Hugging Face cloud infrastructure (no local computation):
223
-
224
- ```python
225
- from bytedream import ByteDreamHFClient
226
-
227
- # Initialize API client
228
- client = ByteDreamHFClient(
229
- repo_id="Enzo8930302/ByteDream",
230
- use_api=True, # Use cloud API
231
- )
232
-
233
- # Generate image in the cloud
234
- image = client.generate(
235
- prompt="A futuristic city at night, cyberpunk style",
236
- num_inference_steps=50,
237
- )
238
-
239
- image.save("output.png")
240
  ```
241
 
242
- ### Complete API Examples
243
 
244
- See `examples_hf_api.py` for comprehensive examples:
245
- - Download models from HF Hub
246
- - Upload trained models
247
- - Deploy to Spaces automatically
248
- - Use cloud inference API
249
- - Batch generation
250
- - Compare local vs cloud inference
251
 
252
- ## Configuration
 
 
 
 
253
 
254
- Edit `config.yaml` for custom settings:
255
- - Model dimensions
256
- - Sampling parameters
257
- - Training hyperparameters
258
- - CPU optimization settings
259
 
260
- ## Performance Optimization
 
 
 
 
261
 
262
- ### CPU Optimization
263
- - OpenVINO integration available
264
- - ONNX runtime support
265
- - Mixed precision (FP16/FP32)
266
- - Batch processing
267
 
268
- ### Memory Management
269
- - Gradient checkpointing
270
- - Model offloading
271
- - Progressive generation
272
 
273
- ## File Structure
274
  ```
275
- Byte Dream/
276
  β”œβ”€β”€ bytedream/ # Core package
277
  β”‚ β”œβ”€β”€ __init__.py
 
278
  β”‚ β”œβ”€β”€ model.py # Model architecture
279
- β”‚ β”œβ”€β”€ pipeline.py # Generation pipeline
280
- β”‚ β”œβ”€β”€ scheduler.py # Diffusion scheduler
281
- β”‚ └── utils.py # Utilities
 
282
  β”œβ”€β”€ train.py # Training script
283
- β”œβ”€β”€ infer.py # Inference script
284
- β”œβ”€β”€ app.py # Gradio web interface
285
- β”œβ”€β”€ config.yaml # Configuration
286
- β”œβ”€β”€ requirements.txt # Dependencies
287
- └── README.md # This file
288
  ```
289
 
290
- ## Examples
291
 
292
- Generate various types of images:
293
- - Digital art and illustrations
294
- - Photorealistic scenes
295
- - Abstract concepts
296
- - Character designs
297
- - Landscapes and environments
 
298
 
299
  ## License
300
 
301
- MIT License - See LICENSE file for details
302
 
303
  ## Citation
304
 
305
- If you use Byte Dream in your research:
306
  ```bibtex
307
  @software{bytedream2024,
308
  title={Byte Dream: CPU-Optimized Text-to-Image Generation},
@@ -310,6 +160,16 @@ If you use Byte Dream in your research:
310
  }
311
  ```
312
 
 
 
 
 
 
 
313
  ## Support
314
 
315
- For issues and questions, please open a GitHub issue or contact the maintainers.
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ language: en
4
+ tags:
5
+ - text-to-image
6
+ - diffusion
7
+ - cpu-optimized
8
+ - bytedream
9
+ - clip
10
+ pipeline_tag: text-to-image
11
+ ---
12
+
13
+ # Byte Dream - Text-to-Image Model
14
 
15
  ## Overview
16
+ Byte Dream is a production-ready text-to-image diffusion model optimized for CPU inference.
17
+ It uses CLIP ViT-B/32 for text encoding and a custom UNet architecture for image generation.
18
 
19
  ## Features
20
+ - βœ… **CPU Optimized**: Runs efficiently on CPU (no GPU required)
21
+ - βœ… **High Quality**: Generates 512x512 images
22
+ - βœ… **Fast Inference**: Optimized for speed
23
+ - βœ… **Easy to Use**: Simple Python API and web interface
24
+ - βœ… **Open Source**: MIT License
 
 
 
25
 
26
  ## Installation
27
 
 
28
  ```bash
29
+ pip install torch pillow transformers
30
+ git lfs install
31
+ git clone https://huggingface.co/Enzo8930302/ByteDream
32
+ cd ByteDream
 
 
 
33
  ```
34
 
35
  ## Usage
36
 
37
+ ### Quick Start
38
  ```python
39
  from bytedream import ByteDreamGenerator
40
 
41
+ # Load model
42
+ generator = ByteDreamGenerator(hf_repo_id="Enzo8930302/ByteDream")
43
 
44
+ # Generate image
45
  image = generator.generate(
46
  prompt="A beautiful sunset over mountains, digital art",
47
  num_inference_steps=50,
48
+ guidance_scale=7.5,
49
  )
 
 
50
  image.save("output.png")
51
  ```
52
 
53
+ ### Using Cloud API
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  ```python
55
+ from bytedream import ByteDreamHFClient
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
+ client = ByteDreamHFClient(
58
+ repo_id="Enzo8930302/ByteDream",
59
+ use_api=True,
 
 
60
  )
61
 
62
+ image = client.generate(
63
+ prompt="Futuristic city at night, cyberpunk",
 
 
 
 
 
64
  )
65
+ image.save("output.png")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  ```
67
 
 
 
 
 
 
 
 
 
68
  ## Training
69
 
70
+ Train on your own dataset:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
  ```bash
73
+ # Create dataset
74
+ python create_test_dataset.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
+ # Train model
77
+ python train.py --config config.yaml --train_data dataset
 
 
 
 
78
  ```
79
 
80
+ ## Web Interface
 
 
 
 
 
 
 
 
 
 
 
81
 
82
+ Launch Gradio web interface:
83
 
 
84
  ```bash
85
+ python app.py
86
  ```
87
 
88
+ Or deploy to Hugging Face Spaces:
 
 
 
 
 
 
 
 
 
89
 
90
+ ```bash
91
+ python deploy_to_spaces.py --repo_id YourUsername/ByteDream-Space
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  ```
93
 
94
+ ## Model Architecture
95
 
96
+ - **Text Encoder**: CLIP ViT-B/32 (512 dimensions)
97
+ - **UNet**: Custom architecture with cross-attention
98
+ - **VAE**: Autoencoder for latent space
99
+ - **Scheduler**: DDIM sampling
 
 
 
100
 
101
+ ### Parameters
102
+ - Cross-attention dimension: 512
103
+ - Block channels: [128, 256, 512, 512]
104
+ - Attention heads: 4
105
+ - Layers per block: 1
106
 
107
+ ## Examples
 
 
 
 
108
 
109
+ ### Prompts that work well:
110
+ - "A serene lake at sunset with mountains"
111
+ - "Futuristic city with flying cars, cyberpunk"
112
+ - "Majestic dragon flying over castle, fantasy"
113
+ - "Peaceful garden with cherry blossoms"
114
 
115
+ ### Tips:
116
+ - Use detailed, descriptive prompts
117
+ - Add style keywords (digital art, oil painting, etc.)
118
+ - Use negative prompts to avoid unwanted elements
119
+ - Higher guidance scale = more faithful to prompt
120
 
121
+ ## Files Structure
 
 
 
122
 
 
123
  ```
124
+ ByteDream/
125
  β”œβ”€β”€ bytedream/ # Core package
126
  β”‚ β”œβ”€β”€ __init__.py
127
+ β”‚ β”œβ”€β”€ generator.py # Main generator
128
  β”‚ β”œβ”€β”€ model.py # Model architecture
129
+ β”‚ β”œβ”€β”€ pipeline.py # Pipeline
130
+ β”‚ β”œβ”€β”€ scheduler.py # Scheduler
131
+ β”‚ β”œβ”€β”€ hf_api.py # HF API client
132
+ β”‚ └��─ utils.py
133
  β”œβ”€β”€ train.py # Training script
134
+ β”œβ”€β”€ infer.py # Inference
135
+ β”œβ”€β”€ app.py # Web UI
136
+ β”œβ”€β”€ config.yaml # Config
137
+ └── requirements.txt # Dependencies
 
138
  ```
139
 
140
+ ## Requirements
141
 
142
+ - Python 3.8+
143
+ - PyTorch
144
+ - Pillow
145
+ - Transformers
146
+ - Gradio (for web UI)
147
+
148
+ See `requirements.txt` for full list.
149
 
150
  ## License
151
 
152
+ MIT License
153
 
154
  ## Citation
155
 
 
156
  ```bibtex
157
  @software{bytedream2024,
158
  title={Byte Dream: CPU-Optimized Text-to-Image Generation},
 
160
  }
161
  ```
162
 
163
+ ## Links
164
+
165
+ - [GitHub](https://github.com/yourusername/bytedream)
166
+ - [Documentation](https://huggingface.co/Enzo8930302/ByteDream/blob/main/README.md)
167
+ - [Spaces Demo](https://huggingface.co/spaces/Enzo8930302/ByteDream-Space)
168
+
169
  ## Support
170
 
171
+ For issues or questions, please open an issue on GitHub.
172
+
173
+ ---
174
+
175
+ **Created by Enzo and the Byte Dream Team** 🎨