Spaces:
Sleeping
Sleeping
Create image_modals.py
Browse files- image_modals.py +30 -0
image_modals.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import io
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
headers = {"Authorization": f"Bearer {os.getenv('ImagiGen_HF_secret')}"}
|
| 7 |
+
def query(API_URL, payload):
|
| 8 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
| 9 |
+
return response.content
|
| 10 |
+
|
| 11 |
+
def flux(prompt):
|
| 12 |
+
image = ""
|
| 13 |
+
API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
|
| 14 |
+
image_bytes = query(
|
| 15 |
+
API_URL,
|
| 16 |
+
{
|
| 17 |
+
"inputs": prompt,
|
| 18 |
+
},
|
| 19 |
+
)
|
| 20 |
+
return image_bytes
|
| 21 |
+
|
| 22 |
+
def stable_diffusion(prompt):
|
| 23 |
+
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-3-medium-diffusers"
|
| 24 |
+
image_bytes = query(
|
| 25 |
+
API_URL,
|
| 26 |
+
{
|
| 27 |
+
"inputs": prompt,
|
| 28 |
+
},
|
| 29 |
+
)
|
| 30 |
+
return image_bytes
|