Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -24,24 +24,17 @@ device = "cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is
|
|
| 24 |
if device == "mps":
|
| 25 |
os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = "1"
|
| 26 |
|
| 27 |
-
# Load model
|
| 28 |
-
@spaces.
|
| 29 |
-
def
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
pipe = StableDiffusionPipeline.from_pretrained(
|
| 33 |
-
model_id,
|
| 34 |
torch_dtype=torch.float16,
|
| 35 |
-
safety_checker=None
|
| 36 |
-
use_safetensors=True
|
| 37 |
).to(device)
|
| 38 |
-
|
| 39 |
-
# Disable unnecessary progress bars
|
| 40 |
-
pipe.set_progress_bar_config(disable=True)
|
| 41 |
-
return pipe
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
pipe =
|
| 45 |
|
| 46 |
# Load concept library
|
| 47 |
concept_embeds, concept_tokens = load_concept_library(pipe)
|
|
@@ -317,4 +310,4 @@ def create_demo():
|
|
| 317 |
# Launch the app
|
| 318 |
if __name__ == "__main__":
|
| 319 |
demo = create_demo()
|
| 320 |
-
demo.launch(debug=False, show_error=True, server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 24 |
if device == "mps":
|
| 25 |
os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = "1"
|
| 26 |
|
| 27 |
+
# Load model with proper caching
|
| 28 |
+
@spaces.GPU
|
| 29 |
+
def load_model():
|
| 30 |
+
return StableDiffusionPipeline.from_pretrained(
|
| 31 |
+
"runwayml/stable-diffusion-v1-5",
|
|
|
|
|
|
|
| 32 |
torch_dtype=torch.float16,
|
| 33 |
+
safety_checker=None
|
|
|
|
| 34 |
).to(device)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
# Create pipeline instance
|
| 37 |
+
pipe = load_model()
|
| 38 |
|
| 39 |
# Load concept library
|
| 40 |
concept_embeds, concept_tokens = load_concept_library(pipe)
|
|
|
|
| 310 |
# Launch the app
|
| 311 |
if __name__ == "__main__":
|
| 312 |
demo = create_demo()
|
| 313 |
+
demo.launch(debug=False, show_error=True, server_name="0.0.0.0", server_port=7860, cache_examples=True)
|