Ffftdtd5dtft commited on
Commit
820691f
·
verified ·
1 Parent(s): 4b20876

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -107,17 +107,18 @@ def edit_image_with_prompt(image_bytes, prompt, strength=0.75):
107
 
108
  def generate_song(prompt, duration=10):
109
  redis_key = f"generated_song:{prompt}:{duration}"
110
- song = load_object_from_redis(redis_key)
111
- if not song:
112
  try:
113
  with tqdm(total=1, desc="Generating song") as pbar:
114
- song = music_gen.generate(prompt, duration=duration)
115
  pbar.update(1)
116
- save_object_to_redis(redis_key, song)
 
117
  except Exception as e:
118
  print(f"Failed to generate song: {e}")
119
  return None
120
- return song
121
 
122
  def generate_text(prompt):
123
  redis_key = f"generated_text:{prompt}"
@@ -125,7 +126,7 @@ def generate_text(prompt):
125
  if not text:
126
  try:
127
  with tqdm(total=1, desc="Generating text") as pbar:
128
- text = text_gen_pipeline([{"role": "user", "content": prompt}], max_new_tokens=256)[0]["generated_text"].strip()
129
  pbar.update(1)
130
  save_object_to_redis(redis_key, text)
131
  except Exception as e:
@@ -162,7 +163,7 @@ def generate_code(prompt):
162
  if not code:
163
  try:
164
  with tqdm(total=1, desc="Generating code") as pbar:
165
- inputs = starcoder_tokenizer.encode(prompt, return_tensors="pt").to("cuda")
166
  outputs = starcoder_model.generate(inputs)
167
  code = starcoder_tokenizer.decode(outputs[0])
168
  pbar.update(1)
@@ -262,7 +263,7 @@ generate_song_tab = gr.Interface(fn=generate_song, inputs=[gr.Textbox(label="Pro
262
  generate_text_tab = gr.Interface(fn=generate_text, inputs=gr.Textbox(label="Prompt:"), outputs=gr.Textbox(label="Generated Text:"), title="Generate Text")
263
  generate_flux_image_tab = gr.Interface(fn=generate_flux_image, inputs=gr.Textbox(label="Prompt:"), outputs=gr.Image(type="pil"), title="Generate FLUX Images")
264
  generate_code_tab = gr.Interface(fn=generate_code, inputs=gr.Textbox(label="Prompt:"), outputs=gr.Textbox(label="Generated Code:"), title="Generate Code")
265
- model_meta_llama_test_tab = gr.Interface(fn=test_model_meta_llama, inputs=gr.Textbox(label="Test Input:"), outputs=gr.Textbox(label="Model Output:"), title="Test Meta-Llama")
266
 
267
  app = gr.TabbedInterface(
268
  [gen_image_tab, edit_image_tab, generate_song_tab, generate_text_tab, generate_flux_image_tab, generate_code_tab, model_meta_llama_test_tab],
 
107
 
108
  def generate_song(prompt, duration=10):
109
  redis_key = f"generated_song:{prompt}:{duration}"
110
+ song_bytes = load_object_from_redis(redis_key)
111
+ if not song_bytes:
112
  try:
113
  with tqdm(total=1, desc="Generating song") as pbar:
114
+ song = music_gen.generate([prompt], duration=[duration])
115
  pbar.update(1)
116
+ song_bytes = song[0].getvalue()
117
+ save_object_to_redis(redis_key, song_bytes)
118
  except Exception as e:
119
  print(f"Failed to generate song: {e}")
120
  return None
121
+ return song_bytes
122
 
123
  def generate_text(prompt):
124
  redis_key = f"generated_text:{prompt}"
 
126
  if not text:
127
  try:
128
  with tqdm(total=1, desc="Generating text") as pbar:
129
+ text = text_gen_pipeline(prompt, max_new_tokens=256)[0]["generated_text"].strip()
130
  pbar.update(1)
131
  save_object_to_redis(redis_key, text)
132
  except Exception as e:
 
163
  if not code:
164
  try:
165
  with tqdm(total=1, desc="Generating code") as pbar:
166
+ inputs = starcoder_tokenizer.encode(prompt, return_tensors="pt").to(starcoder_model.device)
167
  outputs = starcoder_model.generate(inputs)
168
  code = starcoder_tokenizer.decode(outputs[0])
169
  pbar.update(1)
 
263
  generate_text_tab = gr.Interface(fn=generate_text, inputs=gr.Textbox(label="Prompt:"), outputs=gr.Textbox(label="Generated Text:"), title="Generate Text")
264
  generate_flux_image_tab = gr.Interface(fn=generate_flux_image, inputs=gr.Textbox(label="Prompt:"), outputs=gr.Image(type="pil"), title="Generate FLUX Images")
265
  generate_code_tab = gr.Interface(fn=generate_code, inputs=gr.Textbox(label="Prompt:"), outputs=gr.Textbox(label="Generated Code:"), title="Generate Code")
266
+ model_meta_llama_test_tab = gr.Interface(fn=test_model_meta_llama, inputs=None, outputs=gr.Textbox(label="Model Output:"), title="Test Meta-Llama")
267
 
268
  app = gr.TabbedInterface(
269
  [gen_image_tab, edit_image_tab, generate_song_tab, generate_text_tab, generate_flux_image_tab, generate_code_tab, model_meta_llama_test_tab],