Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,19 +4,30 @@ from diffusers import DiffusionPipeline
|
|
4 |
from huggingface_hub import login
|
5 |
import os
|
6 |
|
|
|
|
|
|
|
7 |
# Hugging Face Login Function
|
8 |
@st.cache_resource
|
9 |
def authenticate_and_load_model(hf_token):
|
10 |
"""
|
11 |
-
Log in to Hugging Face
|
12 |
"""
|
13 |
try:
|
14 |
# Log in to Hugging Face
|
15 |
login(token=hf_token)
|
16 |
|
17 |
-
# Load the model
|
18 |
-
pipe = DiffusionPipeline.from_pretrained(
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
return pipe
|
21 |
except Exception as e:
|
22 |
st.error(f"Error during login or model loading: {e}")
|
|
|
4 |
from huggingface_hub import login
|
5 |
import os
|
6 |
|
7 |
+
# Set a custom directory to save the model
|
8 |
+
MODEL_DIR = "./saved_models"
|
9 |
+
|
10 |
# Hugging Face Login Function
|
11 |
@st.cache_resource
|
12 |
def authenticate_and_load_model(hf_token):
|
13 |
"""
|
14 |
+
Log in to Hugging Face, download the model, and save it locally for reuse.
|
15 |
"""
|
16 |
try:
|
17 |
# Log in to Hugging Face
|
18 |
login(token=hf_token)
|
19 |
|
20 |
+
# Load the model and LoRA weights, saving them to the custom directory
|
21 |
+
pipe = DiffusionPipeline.from_pretrained(
|
22 |
+
"black-forest-labs/FLUX.1-dev",
|
23 |
+
cache_dir=MODEL_DIR,
|
24 |
+
use_auth_token=hf_token
|
25 |
+
)
|
26 |
+
pipe.load_lora_weights(
|
27 |
+
"tryonlabs/FLUX.1-dev-LoRA-Lehenga-Generator",
|
28 |
+
cache_dir=MODEL_DIR,
|
29 |
+
use_auth_token=hf_token
|
30 |
+
)
|
31 |
return pipe
|
32 |
except Exception as e:
|
33 |
st.error(f"Error during login or model loading: {e}")
|