Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,25 @@
|
|
1 |
-
|
2 |
-
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
import random
|
6 |
import spaces
|
7 |
import torch
|
|
|
8 |
from diffusers import DiffusionPipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
|
|
10 |
dtype = torch.bfloat16
|
11 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
12 |
|
|
|
13 |
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=dtype).to(device)
|
14 |
|
15 |
MAX_SEED = np.iinfo(np.int32).max
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import random
|
4 |
import spaces
|
5 |
import torch
|
6 |
+
import os
|
7 |
from diffusers import DiffusionPipeline
|
8 |
+
from huggingface_hub import login
|
9 |
+
|
10 |
+
# Access the API token securely from Hugging Face Secrets
|
11 |
+
hf_api_token = os.getenv("HF_API_TOKEN")
|
12 |
+
|
13 |
+
if hf_api_token:
|
14 |
+
login(token=hf_api_token)
|
15 |
+
else:
|
16 |
+
raise ValueError("Hugging Face API token not found in secrets.")
|
17 |
|
18 |
+
# Set the device and dtype
|
19 |
dtype = torch.bfloat16
|
20 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
21 |
|
22 |
+
# Load the diffusion pipeline from the gated repository
|
23 |
pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=dtype).to(device)
|
24 |
|
25 |
MAX_SEED = np.iinfo(np.int32).max
|