Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import torch
|
| 4 |
+
import os
|
| 5 |
+
import logging
|
| 6 |
+
import psutil
|
| 7 |
+
|
| 8 |
+
# Configure logging
|
| 9 |
+
logging.basicConfig(level=logging.INFO)
|
| 10 |
+
logger = logging.getLogger(__name__)
|
| 11 |
+
|
| 12 |
+
def print_memory_info():
|
| 13 |
+
# Get free CPU memory
|
| 14 |
+
virtual_mem = psutil.virtual_memory()
|
| 15 |
+
free_cpu_mem = virtual_mem.available / (1024 ** 3) # Convert bytes to GB
|
| 16 |
+
|
| 17 |
+
# Get free GPU memory
|
| 18 |
+
free_gpu_mem = torch.cuda.get_device_properties(0).total_memory / (1024 ** 3) - torch.cuda.memory_reserved(0) / (1024 ** 3) # Convert bytes to GB
|
| 19 |
+
|
| 20 |
+
logger.info(f"Free CPU Memory: {free_cpu_mem:.2f} GB")
|
| 21 |
+
logger.info(f"Free GPU Memory: {free_gpu_mem:.2f} GB")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# @st.cache_resource
|
| 25 |
+
def load_image_model():
|
| 26 |
+
print_memory_info()
|
| 27 |
+
torch.cuda.empty_cache()
|
| 28 |
+
pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", variant='fp16')
|
| 29 |
+
pipeline.to("cuda")
|
| 30 |
+
pipeline.load_lora_weights("Weights/pytorch_lora_weights.safetensors", weight_name="pytorch_lora_weights.safetensors")
|
| 31 |
+
return pipeline
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
image_service = load_image_model()
|
| 35 |
+
|