Spaces:
Running
on
Zero
Running
on
Zero
czd358121692
commited on
Commit
•
5399123
1
Parent(s):
4a639bf
check disk space
Browse files
app.py
CHANGED
@@ -32,6 +32,7 @@ audio_model = None
|
|
32 |
audio_config = None
|
33 |
|
34 |
def initialize_models():
|
|
|
35 |
global kosmos_model, kosmos_processor, zephyr_pipe, audio_model, audio_config
|
36 |
try:
|
37 |
print("Loading Kosmos-2...")
|
@@ -47,6 +48,8 @@ def initialize_models():
|
|
47 |
except Exception as e:
|
48 |
print(f"Error loading Kosmos-2: {e}")
|
49 |
raise
|
|
|
|
|
50 |
try:
|
51 |
print("Loading Zephyr...")
|
52 |
zephyr_pipe = pipeline(
|
@@ -59,6 +62,7 @@ def initialize_models():
|
|
59 |
print(f"Error loading Zephyr: {e}")
|
60 |
raise
|
61 |
|
|
|
62 |
try:
|
63 |
print("Loading Stable Audio...")
|
64 |
audio_model, audio_config = get_pretrained_model("stabilityai/stable-audio-open-1.0")
|
@@ -67,12 +71,14 @@ def initialize_models():
|
|
67 |
except Exception as e:
|
68 |
print(f"Error loading Stable Audio: {e}")
|
69 |
raise
|
|
|
70 |
|
71 |
def get_caption(image_in):
|
72 |
if not image_in:
|
73 |
raise gr.Error("Please provide an image")
|
74 |
|
75 |
try:
|
|
|
76 |
# Convert image to PIL if needed
|
77 |
if isinstance(image_in, str):
|
78 |
image = Image.open(image_in)
|
@@ -116,6 +122,7 @@ def get_musical_prompt(user_prompt, chosen_model):
|
|
116 |
raise gr.Error("No image caption provided")
|
117 |
|
118 |
try:
|
|
|
119 |
standard_sys = """
|
120 |
You are a musician AI who specializes in translating architectural spaces into musical experiences. Your job is to create concise musical descriptions that capture the essence of architectural photographs.
|
121 |
|
@@ -173,6 +180,7 @@ def get_stable_audio_open(prompt, seconds_total=47, steps=100, cfg_scale=7):
|
|
173 |
try:
|
174 |
torch.cuda.empty_cache() # Clear GPU memory before generation
|
175 |
|
|
|
176 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
177 |
sample_rate = audio_config["sample_rate"]
|
178 |
sample_size = audio_config["sample_size"]
|
@@ -226,6 +234,17 @@ def get_storage_info():
|
|
226 |
percent = disk_usage.percent
|
227 |
return f"Storage: {used}/{total} ({percent}% used)"
|
228 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
def smart_cleanup():
|
230 |
try:
|
231 |
cache_info = scan_cache_dir()
|
|
|
32 |
audio_config = None
|
33 |
|
34 |
def initialize_models():
|
35 |
+
check_disk_space()
|
36 |
global kosmos_model, kosmos_processor, zephyr_pipe, audio_model, audio_config
|
37 |
try:
|
38 |
print("Loading Kosmos-2...")
|
|
|
48 |
except Exception as e:
|
49 |
print(f"Error loading Kosmos-2: {e}")
|
50 |
raise
|
51 |
+
|
52 |
+
check_disk_space()
|
53 |
try:
|
54 |
print("Loading Zephyr...")
|
55 |
zephyr_pipe = pipeline(
|
|
|
62 |
print(f"Error loading Zephyr: {e}")
|
63 |
raise
|
64 |
|
65 |
+
check_disk_space()
|
66 |
try:
|
67 |
print("Loading Stable Audio...")
|
68 |
audio_model, audio_config = get_pretrained_model("stabilityai/stable-audio-open-1.0")
|
|
|
71 |
except Exception as e:
|
72 |
print(f"Error loading Stable Audio: {e}")
|
73 |
raise
|
74 |
+
check_disk_space()
|
75 |
|
76 |
def get_caption(image_in):
|
77 |
if not image_in:
|
78 |
raise gr.Error("Please provide an image")
|
79 |
|
80 |
try:
|
81 |
+
check_disk_space()
|
82 |
# Convert image to PIL if needed
|
83 |
if isinstance(image_in, str):
|
84 |
image = Image.open(image_in)
|
|
|
122 |
raise gr.Error("No image caption provided")
|
123 |
|
124 |
try:
|
125 |
+
check_disk_space()
|
126 |
standard_sys = """
|
127 |
You are a musician AI who specializes in translating architectural spaces into musical experiences. Your job is to create concise musical descriptions that capture the essence of architectural photographs.
|
128 |
|
|
|
180 |
try:
|
181 |
torch.cuda.empty_cache() # Clear GPU memory before generation
|
182 |
|
183 |
+
check_disk_space()
|
184 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
185 |
sample_rate = audio_config["sample_rate"]
|
186 |
sample_size = audio_config["sample_size"]
|
|
|
234 |
percent = disk_usage.percent
|
235 |
return f"Storage: {used}/{total} ({percent}% used)"
|
236 |
|
237 |
+
def check_disk_space(min_gb=10):
|
238 |
+
"""Check if there's enough disk space (default: 10GB)"""
|
239 |
+
disk_usage = psutil.disk_usage('/')
|
240 |
+
gb_free = disk_usage.free / (1024 * 1024 * 1024)
|
241 |
+
if gb_free < min_gb:
|
242 |
+
print("Disk space: {gb_free:.1f}GB free")
|
243 |
+
raise RuntimeError(f"Low disk space: {gb_free:.1f}GB free, need {min_gb}GB")
|
244 |
+
else:
|
245 |
+
print("Disk space: {gb_free:.1f}GB free")
|
246 |
+
return True
|
247 |
+
|
248 |
def smart_cleanup():
|
249 |
try:
|
250 |
cache_info = scan_cache_dir()
|