admin commited on
Commit
7ea4f7d
·
1 Parent(s): 1436450
Files changed (3) hide show
  1. app.py +32 -48
  2. requirements.txt +4 -4
  3. utils.py +3 -5
app.py CHANGED
@@ -172,20 +172,23 @@ def generate_music(args, region: str):
172
  audio = xml2(xml, "wav")
173
  pdf, jpg = xml2img(xml)
174
  mxl = xml2(xml, "mxl")
175
- return tunes, midi, pdf, xml, mxl, jpg, audio
176
 
177
  except Exception as e:
178
  print(f"Invalid abc generated: {e}, retrying...")
179
  return generate_music(args, region)
180
 
181
 
182
- def infer(region: str):
183
  if os.path.exists(TEMP_DIR):
184
  shutil.rmtree(TEMP_DIR)
185
 
186
  os.makedirs(TEMP_DIR, exist_ok=True)
187
  parser = argparse.ArgumentParser()
188
  args = get_args(parser)
 
 
 
189
  if region == "Natlan":
190
  region = "Teyvat"
191
 
@@ -194,49 +197,30 @@ def infer(region: str):
194
 
195
  if __name__ == "__main__":
196
  warnings.filterwarnings("ignore")
197
- with gr.Blocks() as demo:
198
- with gr.Row():
199
- with gr.Column():
200
- region_opt = gr.Dropdown(
201
- choices=TEYVAT,
202
- value="Mondstadt",
203
- label="Region",
204
- )
205
- gen_btn = gr.Button("Generate")
206
- gr.Markdown(
207
- """
208
- Welcome to this space based on the Tunesformer open source project, which is totally free!
209
-
210
- The current model is still in debugging, the plan is in the Genshin Impact after the main line is killed, all countries and regions after all the characters are open, the second creation of the concert will be complete and the sample is balanced, at that time to re-fine-tune the model and add the reality of the style of screening to assist in the game of each country's output to strengthen the learning in order to enhance the output differentiation and quality.
211
-
212
- Data source: <a href="https://musescore.org">MuseScore</a><br>
213
- Tags source: <a href="https://genshin-impact.fandom.com/wiki/Genshin_Impact_Wiki">Genshin Impact Wiki | Fandom</a><br>
214
- Model base: <a href="https://github.com/sander-wood/tunesformer">Tunesformer</a>
215
-
216
- Note: Data engineering on the Star Rail is in operation, and will hopefully be baselined in the future as well with the mainline kill."""
217
- )
218
-
219
- with gr.Column():
220
- wav_output = gr.Audio(label="Audio", type="filepath")
221
- dld_midi = gr.File(label="Download MIDI")
222
- pdf_score = gr.File(label="Download PDF")
223
- dld_xml = gr.File(label="Download MusicXML")
224
- dld_mxl = gr.File(label="Download MXL")
225
- abc_output = gr.Textbox(label="ABC notation", show_copy_button=True)
226
- img_score = gr.Image(label="Staff", type="filepath")
227
-
228
- gen_btn.click(
229
- infer,
230
- inputs=region_opt,
231
- outputs=[
232
- abc_output,
233
- dld_midi,
234
- pdf_score,
235
- dld_xml,
236
- dld_mxl,
237
- img_score,
238
- wav_output,
239
- ],
240
- )
241
-
242
- demo.launch()
 
172
  audio = xml2(xml, "wav")
173
  pdf, jpg = xml2img(xml)
174
  mxl = xml2(xml, "mxl")
175
+ return audio, midi, pdf, xml, mxl, tunes, jpg
176
 
177
  except Exception as e:
178
  print(f"Invalid abc generated: {e}, retrying...")
179
  return generate_music(args, region)
180
 
181
 
182
+ def infer(p, k, t, region: str):
183
  if os.path.exists(TEMP_DIR):
184
  shutil.rmtree(TEMP_DIR)
185
 
186
  os.makedirs(TEMP_DIR, exist_ok=True)
187
  parser = argparse.ArgumentParser()
188
  args = get_args(parser)
189
+ args.top_p = p
190
+ args.top_k = k
191
+ args.temperature = t
192
  if region == "Natlan":
193
  region = "Teyvat"
194
 
 
197
 
198
  if __name__ == "__main__":
199
  warnings.filterwarnings("ignore")
200
+ gr.Interface(
201
+ fn=infer,
202
+ inputs=[
203
+ gr.Slider(0, 1.0, 0.8, label="Top-P sample"),
204
+ gr.Slider(0, 80, 8, label="Top-K sample (0=closed)"),
205
+ gr.Slider(0, 2.0, 1.2, label="Temperature"),
206
+ gr.Dropdown(
207
+ choices=TEYVAT,
208
+ value="Mondstadt",
209
+ label="Region",
210
+ ),
211
+ ],
212
+ outputs=[
213
+ gr.Audio(label="Audio", type="filepath"),
214
+ gr.File(label="Download MIDI"),
215
+ gr.File(label="Download PDF"),
216
+ gr.File(label="Download MusicXML"),
217
+ gr.File(label="Download MXL"),
218
+ gr.Textbox(label="ABC notation", show_copy_button=True),
219
+ gr.Image(label="Staff", type="filepath"),
220
+ ],
221
+ flagging_mode="never",
222
+ description="""
223
+ Welcome to this space based on the Tunesformer open source project, which is totally free! The current model is still in debugging, the plan is in the Genshin Impact after the main line is killed, all countries and regions after all the characters are open, the second creation of the concert will be complete and the sample is balanced, at that time to re-fine-tune the model and add the reality of the style of screening to assist in the game of each country's output to strengthen the learning in order to enhance the output differentiation and quality. Note: Data engineering on the Star Rail is in operation, and will hopefully be baselined in the future as well with the mainline kill.<br>
224
+ Data source: <a href="https://musescore.org">MuseScore</a> Tags source: <a href="https://genshin-impact.fandom.com/wiki/Genshin_Impact_Wiki">Genshin Impact Wiki | Fandom</a> Model base: <a href="https://github.com/sander-wood/tunesformer">Tunesformer</a>
225
+ """,
226
+ ).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -3,8 +3,8 @@ music21
3
  pymupdf
4
  autopep8
5
  unidecode
6
- modelscope[framework]==1.18
7
- transformers==4.18.0
8
- samplings==0.1.7
9
  pillow==9.4.0
10
- numpy==1.26.4
 
 
 
 
3
  pymupdf
4
  autopep8
5
  unidecode
 
 
 
6
  pillow==9.4.0
7
+ numpy==1.26.4
8
+ samplings==0.1.7
9
+ transformers==4.18.0
10
+ modelscope[framework]==1.18
utils.py CHANGED
@@ -13,15 +13,13 @@ WEIGHTS_PATH = (
13
  + "/weights.pth"
14
  )
15
  DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
16
- TEMP_DIR = "./flagged"
17
  PATCH_LENGTH = 128 # Patch Length
18
  PATCH_SIZE = 32 # Patch Size
19
  PATCH_NUM_LAYERS = 9 # Number of layers in the encoder
20
  CHAR_NUM_LAYERS = 3 # Number of layers in the decoder
21
- # Batch size for patch during training, 0 for full context
22
- PATCH_SAMPLING_BATCH_SIZE = 0
23
- # Whether to share weights between the encoder and decoder
24
- SHARE_WEIGHTS = False
25
 
26
 
27
  def download(filename: str, url: str):
 
13
  + "/weights.pth"
14
  )
15
  DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
16
+ TEMP_DIR = "./__pycache__/tmp"
17
  PATCH_LENGTH = 128 # Patch Length
18
  PATCH_SIZE = 32 # Patch Size
19
  PATCH_NUM_LAYERS = 9 # Number of layers in the encoder
20
  CHAR_NUM_LAYERS = 3 # Number of layers in the decoder
21
+ PATCH_SAMPLING_BATCH_SIZE = 0 # Batchsize for patch during training, 0=full context
22
+ SHARE_WEIGHTS = False # Whether to share weights between the encoder and decoder
 
 
23
 
24
 
25
  def download(filename: str, url: str):