Download app/models/StableDiffusionAPI/StableDiffusionV2.py from savetrees/StegNet: direct link, hf CLI and curl.
- Browser
- Download file 628 Bytes
-
https://huggingface.co/spaces/savetrees/StegNet/resolve/main/app/models/StableDiffusionAPI/StableDiffusionV2.py
- Command line
-
hf download hf://spaces/savetrees/StegNet/app/models/StableDiffusionAPI/StableDiffusionV2.py
-
curl -L -o StableDiffusionV2.py https://huggingface.co/spaces/savetrees/StegNet/resolve/main/app/models/StableDiffusionAPI/StableDiffusionV2.py
628 Bytes
| import os | |
| import requests | |
| import io | |
| from PIL import Image | |
| API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2-1" | |
| def generate(text_prompt): | |
| api_key = os.environ.get("HF_API_KEY", "") | |
| if not api_key: | |
| raise ValueError("HF_API_KEY environment variable is not set.") | |
| response = requests.post( | |
| API_URL, | |
| headers={"Authorization": f"Bearer {api_key}"}, | |
| json={"inputs": text_prompt}, | |
| ) | |
| response.raise_for_status() | |
| return Image.open(io.BytesIO(response.content)) | |
| """ | |
| text = input("Your sentence here:") | |
| image = generate(text) | |
| image.show() | |
| """ |