czd358121692 commited on
Commit
d5f2ccb
β€’
1 Parent(s): d0d23d6

add credits and features

Browse files
Files changed (1) hide show
  1. app.py +41 -12
app.py CHANGED
@@ -18,7 +18,6 @@ from huggingface_hub import scan_cache_dir
18
  from stable_audio_tools import get_pretrained_model
19
  from stable_audio_tools.inference.generation import generate_diffusion_cond
20
 
21
- # Cache setup code remains same
22
  CACHE_ROOT = '/tmp'
23
  os.environ['HF_HOME'] = CACHE_ROOT
24
  os.environ['HUGGINGFACE_HUB_CACHE'] = os.path.join(CACHE_ROOT, 'hub')
@@ -117,7 +116,7 @@ def get_caption(image_in):
117
 
118
  # Continuing from previous code...
119
 
120
- def get_musical_prompt(user_prompt, chosen_model):
121
  if not user_prompt:
122
  raise gr.Error("No image caption provided")
123
 
@@ -134,6 +133,12 @@ Consider these elements in your composition:
134
  - Soundscapes: environmental depth and spatial audio qualities
135
 
136
  Respond immediately with a single musical prompt. No explanation, just the musical description.
 
 
 
 
 
 
137
  """
138
  instruction = f"""
139
  <|system|>
@@ -154,7 +159,7 @@ Respond immediately with a single musical prompt. No explanation, just the music
154
  musical_prompt = outputs[0]["generated_text"]
155
 
156
  # Clean system message and tokens
157
- cleaned_prompt = musical_prompt.replace("<|system|>", "").replace("</s>", "").replace("<|user|>", "").replace("<|assistant|>", "")
158
 
159
  lines = cleaned_prompt.split('\n')
160
  relevant_lines = [line.strip() for line in lines
@@ -174,7 +179,8 @@ Respond immediately with a single musical prompt. No explanation, just the music
174
 
175
  except Exception as e:
176
  print(f"Error in get_musical_prompt: {str(e)}")
177
- return "Ambient orchestral composition with piano and strings, creating a contemplative atmosphere"
 
178
 
179
  def get_stable_audio_open(prompt, seconds_total=47, steps=100, cfg_scale=7):
180
  try:
@@ -239,10 +245,10 @@ def check_disk_space(min_gb=10):
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" + str(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" + str(gb_free))
246
  return True
247
 
248
  def smart_cleanup():
@@ -289,7 +295,7 @@ def infer(image_in, api_status):
289
  if image_in is None:
290
  raise gr.Error("Please provide an image of architecture")
291
 
292
- if api_status == "Orchestra is tuning...":
293
  raise gr.Error("The model is still tuning, please try again later")
294
 
295
  try:
@@ -297,7 +303,7 @@ def infer(image_in, api_status):
297
  user_prompt = get_caption(image_in)
298
 
299
  gr.Info("🎼 Weaving into melody...")
300
- musical_prompt = get_musical_prompt(user_prompt, "Stable Audio Open")
301
 
302
  gr.Info("🎻 Breathing life into notes...")
303
  music_o = get_stable_audio_open(musical_prompt)
@@ -366,13 +372,36 @@ with gr.Blocks(css=css) as demo:
366
  )
367
  retry_btn = gr.Button("🎲", visible=False)
368
  result = gr.Audio(
369
- label="Music"
 
370
  )
371
 
372
- # Credits section remains the same
373
  gr.HTML("""
374
  <div style="margin-top: 40px; padding: 20px; border-top: 1px solid #ddd;">
375
- <!-- Your existing credits HTML -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
376
  </div>
377
  """)
378
 
 
18
  from stable_audio_tools import get_pretrained_model
19
  from stable_audio_tools.inference.generation import generate_diffusion_cond
20
 
 
21
  CACHE_ROOT = '/tmp'
22
  os.environ['HF_HOME'] = CACHE_ROOT
23
  os.environ['HUGGINGFACE_HUB_CACHE'] = os.path.join(CACHE_ROOT, 'hub')
 
116
 
117
  # Continuing from previous code...
118
 
119
+ def get_musical_prompt(user_prompt):
120
  if not user_prompt:
121
  raise gr.Error("No image caption provided")
122
 
 
133
  - Soundscapes: environmental depth and spatial audio qualities
134
 
135
  Respond immediately with a single musical prompt. No explanation, just the musical description.
136
+ Examples:
137
+ Input: "A curved titanium facade reflecting sunlight with flowing organic forms"
138
+ Output: "Fluid jazz piano with shimmering orchestral textures, metallic percussion accents, and expansive reverb creating architectural depth"
139
+
140
+ Input: "A geometric glass atrium with intersecting angular planes"
141
+ Output: "Crystalline minimalist composition with layered string harmonies and precise rhythmic structures, emphasizing spatial transparency"
142
  """
143
  instruction = f"""
144
  <|system|>
 
159
  musical_prompt = outputs[0]["generated_text"]
160
 
161
  # Clean system message and tokens
162
+ cleaned_prompt = musical_prompt.replace("<|system|>", "").replace("</s>", "").replace("<|user|>", "").replace("<|assistant|>", "").replace("Output:", "")
163
 
164
  lines = cleaned_prompt.split('\n')
165
  relevant_lines = [line.strip() for line in lines
 
179
 
180
  except Exception as e:
181
  print(f"Error in get_musical_prompt: {str(e)}")
182
+ final_prompt = "Ambient orchestral composition with piano and strings, creating a contemplative atmosphere"
183
+ return final_prompt
184
 
185
  def get_stable_audio_open(prompt, seconds_total=47, steps=100, cfg_scale=7):
186
  try:
 
245
  disk_usage = psutil.disk_usage('/')
246
  gb_free = disk_usage.free / (1024 * 1024 * 1024)
247
  if gb_free < min_gb:
248
+ print("Disk space GB free: " + str(int(gb_free)))
249
+ raise RuntimeError(f"Low disk space: {int(gb_free)}GB free, need {min_gb}GB")
250
  else:
251
+ print("Disk space GB free: " + str(int(gb_free)))
252
  return True
253
 
254
  def smart_cleanup():
 
295
  if image_in is None:
296
  raise gr.Error("Please provide an image of architecture")
297
 
298
+ if api_status == "Orchestra is tuning. Please refresh the webpage.":
299
  raise gr.Error("The model is still tuning, please try again later")
300
 
301
  try:
 
303
  user_prompt = get_caption(image_in)
304
 
305
  gr.Info("🎼 Weaving into melody...")
306
+ musical_prompt = get_musical_prompt(user_prompt)
307
 
308
  gr.Info("🎻 Breathing life into notes...")
309
  music_o = get_stable_audio_open(musical_prompt)
 
372
  )
373
  retry_btn = gr.Button("🎲", visible=False)
374
  result = gr.Audio(
375
+ label="Music",
376
+ autoplay = True
377
  )
378
 
379
+ # Credits section
380
  gr.HTML("""
381
  <div style="margin-top: 40px; padding: 20px; border-top: 1px solid #ddd;">
382
+ <h3 style="text-align: center;">Credits & Acknowledgments</h3>
383
+
384
+ <h4>Architecture</h4>
385
+ <p>Frank O Gehry, Gehry Partners LLP and Gehry Tech team for pushing the boundaries of form and space for humanity.</p>
386
+
387
+ <h4>Technologies</h4>
388
+ <ul>
389
+ <li>Music Generation: <a href="https://huggingface.co/spaces/harmonai/stable-audio-public">Stable Audio Open</a> by STABILITY AI LTD</li>
390
+ <li>Image Understanding: <a href="https://huggingface.co/microsoft/kosmos-2">Kosmos-2</a> by Microsoft</li>
391
+ <li>Language Model: Zephyr by Hugging Face</li>
392
+ <li>Affordable Online Hosting Platform & Computational Resources by Hugging Face</li>
393
+ </ul>
394
+ <h4>Contributors</h4>
395
+ <ul>
396
+ <li>Architects, Engineers & Consultants who bring these visions to life</li>
397
+ <li>Contractor teams, craftspeople, and workers who materialize these dreams</li>
398
+ <li>Photographers who capture and share these architectural moments to general public online</li>
399
+ <li>Musicians and composers whose work inspires our audio training behind the scenes for generations</li>
400
+ </ul>
401
+ <p style="text-align: center; margin-top: 20px; font-size: 0.9em;">
402
+ This project stands on the shoulders of countless individuals who contribute to the intersection of architecture, technology, and broader arts.
403
+ <br>Special thanks to all the open-source communities and researchers making these technologies accessible.
404
+ </p>
405
  </div>
406
  """)
407