fffiloni commited on
Commit
682c6da
1 Parent(s): 9a1be56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -113,26 +113,26 @@ instruction = f"""
113
  """
114
 
115
  @spaces.GPU(enable_queue=True, duration=60)
116
- def infer(image_in):
117
- gr.Info("Getting image caption with Kosmos2...")
118
- user_prompt = get_caption(image_in)
119
-
120
  prompt = f"{instruction.strip()}\n{user_prompt}</s>"
121
- #print(f"PROMPT: {prompt}")
122
-
123
- gr.Info("Building a musical prompt according to the image caption ...")
124
  outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
125
-
126
-
127
  pattern = r'\<\|system\|\>(.*?)\<\|assistant\|\>'
128
  cleaned_text = re.sub(pattern, '', outputs[0]["generated_text"], flags=re.DOTALL)
129
 
130
  print(f"SUGGESTED Musical prompt: {cleaned_text}")
 
 
 
 
 
 
 
 
131
 
132
  gr.Info("Now calling MAGNet for music ...")
133
- music_o = get_magnet(cleaned_text)
134
 
135
- return cleaned_text.lstrip("\n"), music_o
136
 
137
  demo_title = "Image to Music V2"
138
  description = "Get music from a picture"
 
113
  """
114
 
115
  @spaces.GPU(enable_queue=True, duration=60)
116
+ def get_musical_prompt(user_prompt):
 
 
 
117
  prompt = f"{instruction.strip()}\n{user_prompt}</s>"
 
 
 
118
  outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
 
 
119
  pattern = r'\<\|system\|\>(.*?)\<\|assistant\|\>'
120
  cleaned_text = re.sub(pattern, '', outputs[0]["generated_text"], flags=re.DOTALL)
121
 
122
  print(f"SUGGESTED Musical prompt: {cleaned_text}")
123
+ return cleaned_text.lstrip("\n")
124
+
125
+ def infer(image_in):
126
+ gr.Info("Getting image caption with Kosmos2...")
127
+ user_prompt = get_caption(image_in)
128
+
129
+ gr.Info("Building a musical prompt according to the image caption ...")
130
+ musical_prompt = get_musical_prompt(user_prompt)
131
 
132
  gr.Info("Now calling MAGNet for music ...")
133
+ music_o = get_magnet(musical_prompt)
134
 
135
+ return cleaned_text, music_o
136
 
137
  demo_title = "Image to Music V2"
138
  description = "Get music from a picture"