fix launch for hf
Browse files- README.md +53 -4
- controlnet_pipeline.py +4 -1
- main.py +2 -7
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -5,10 +5,59 @@ colorFrom: pink
|
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.22.0
|
| 8 |
-
app_file:
|
| 9 |
pinned: false
|
| 10 |
-
license:
|
| 11 |
-
short_description: Generate and edit images
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.22.0
|
| 8 |
+
app_file: main.py
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
+
short_description: Generate and edit images with diffusion models and ControlNet
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Diffusion Models App
|
| 15 |
+
|
| 16 |
+
A unified interface for text-to-image and image-to-image generation using Hugging Face models.
|
| 17 |
+
|
| 18 |
+
## Features
|
| 19 |
+
|
| 20 |
+
- πΌοΈ **Text to Image**: Generate images from text prompts
|
| 21 |
+
- π **Image to Image**: Transform images using text prompts
|
| 22 |
+
- π§ **ControlNet Support**: Built-in ControlNet depth model for enhanced image transformations
|
| 23 |
+
- π **Flexible Models**: Use inference endpoints or on-device models
|
| 24 |
+
- π **Dual Interface**: Web UI and API endpoints
|
| 25 |
+
|
| 26 |
+
## Deployment Notes
|
| 27 |
+
|
| 28 |
+
### IMPORTANT: Using ControlNet on Hugging Face Spaces
|
| 29 |
+
|
| 30 |
+
For ControlNet to work correctly:
|
| 31 |
+
|
| 32 |
+
1. Import `spaces` before any `torch` or CUDA-related imports
|
| 33 |
+
2. Select GPU hardware in Space settings
|
| 34 |
+
3. Add your HF_TOKEN as a Repository Secret (Settings β Repository Secrets)
|
| 35 |
+
4. Do NOT commit any sensitive tokens to the repository
|
| 36 |
+
|
| 37 |
+
If you encounter CUDA initialization errors, ensure spaces package is imported first.
|
| 38 |
+
|
| 39 |
+
## Usage
|
| 40 |
+
|
| 41 |
+
### Text to Image
|
| 42 |
+
1. Enter your text prompt
|
| 43 |
+
2. Optionally provide a negative prompt to exclude unwanted elements
|
| 44 |
+
3. Choose a model or use the default
|
| 45 |
+
4. Click "Generate Image"
|
| 46 |
+
|
| 47 |
+
### Image to Image
|
| 48 |
+
1. Upload an image
|
| 49 |
+
2. Enter a prompt to guide the transformation
|
| 50 |
+
3. Choose between HF inference API or ControlNet on-device model
|
| 51 |
+
4. Click "Transform Image"
|
| 52 |
+
|
| 53 |
+
---
|
| 54 |
+
|
| 55 |
+
tags:
|
| 56 |
+
- diffusers
|
| 57 |
+
- stable-diffusion
|
| 58 |
+
- text-to-image
|
| 59 |
+
- image-to-image
|
| 60 |
+
- depth-estimation
|
| 61 |
+
- controlnet
|
| 62 |
+
- spaces
|
| 63 |
+
- huggingface-hub
|
controlnet_pipeline.py
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import numpy as np
|
| 3 |
from PIL import Image
|
|
@@ -6,7 +10,6 @@ from diffusers import StableDiffusionControlNetPipeline, ControlNetModel, UniPCM
|
|
| 6 |
from diffusers.utils import load_image
|
| 7 |
import os
|
| 8 |
import huggingface_hub
|
| 9 |
-
import spaces
|
| 10 |
import config
|
| 11 |
|
| 12 |
class ControlNetPipeline:
|
|
|
|
| 1 |
+
# Import spaces before any CUDA/torch imports
|
| 2 |
+
import spaces
|
| 3 |
+
|
| 4 |
+
# Other imports below
|
| 5 |
import torch
|
| 6 |
import numpy as np
|
| 7 |
from PIL import Image
|
|
|
|
| 10 |
from diffusers.utils import load_image
|
| 11 |
import os
|
| 12 |
import huggingface_hub
|
|
|
|
| 13 |
import config
|
| 14 |
|
| 15 |
class ControlNetPipeline:
|
main.py
CHANGED
|
@@ -36,13 +36,8 @@ def main():
|
|
| 36 |
|
| 37 |
# Check if HF_TOKEN is set
|
| 38 |
if not config.HF_TOKEN:
|
| 39 |
-
print("
|
| 40 |
-
print("
|
| 41 |
-
print("WARNING: HF_TOKEN environment variable is not set!")
|
| 42 |
-
print("* For local development: Create a .env file with HF_TOKEN=your_token")
|
| 43 |
-
print("* For Hugging Face Spaces: Add HF_TOKEN as a secret in your Space settings")
|
| 44 |
-
print("*" * 80)
|
| 45 |
-
print("\n")
|
| 46 |
|
| 47 |
if args.mode == "all":
|
| 48 |
# Run both API and UI in separate threads
|
|
|
|
| 36 |
|
| 37 |
# Check if HF_TOKEN is set
|
| 38 |
if not config.HF_TOKEN:
|
| 39 |
+
print("Warning: HF_TOKEN environment variable is not set. Please set it for API access.")
|
| 40 |
+
print("You can create a .env file with HF_TOKEN=your_token or set it in your environment.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
if args.mode == "all":
|
| 43 |
# Run both API and UI in separate threads
|
requirements.txt
CHANGED
|
@@ -7,6 +7,6 @@ python-dotenv
|
|
| 7 |
torch
|
| 8 |
transformers
|
| 9 |
diffusers
|
| 10 |
-
spaces
|
| 11 |
xformers
|
| 12 |
numpy
|
|
|
|
| 7 |
torch
|
| 8 |
transformers
|
| 9 |
diffusers
|
| 10 |
+
spaces>=0.14.0
|
| 11 |
xformers
|
| 12 |
numpy
|