asigalov61 commited on
Commit
df03c6b
1 Parent(s): 133ccd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -1
app.py CHANGED
@@ -11,4 +11,59 @@ from huggingface_hub import hf_hub_download
11
 
12
  import TMIDIX
13
 
14
- in_space = os.getenv("SYSTEM") == "spaces"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  import TMIDIX
13
 
14
+ in_space = os.getenv("SYSTEM") == "spaces"
15
+
16
+ providers = ['CUDAExecutionProvider', 'CPUExecutionProvider']
17
+
18
+
19
+ def load_javascript(dir="javascript"):
20
+ scripts_list = glob.glob(f"{dir}/*.js")
21
+ javascript = ""
22
+ for path in scripts_list:
23
+ with open(path, "r", encoding="utf8") as jsfile:
24
+ javascript += f"\n<!-- {path} --><script>{jsfile.read()}</script>"
25
+ template_response_ori = gr.routes.templates.TemplateResponse
26
+
27
+ def template_response(*args, **kwargs):
28
+ res = template_response_ori(*args, **kwargs)
29
+ res.body = res.body.replace(
30
+ b'</head>', f'{javascript}</head>'.encode("utf8"))
31
+ res.init_headers()
32
+ return res
33
+
34
+ gr.routes.templates.TemplateResponse = template_response
35
+
36
+
37
+ class JSMsgReceiver(gr.HTML):
38
+
39
+ def __init__(self, **kwargs):
40
+ super().__init__(elem_id="msg_receiver", visible=False, **kwargs)
41
+
42
+ def postprocess(self, y):
43
+ if y:
44
+ y = f"<p>{json.dumps(y)}</p>"
45
+ return super().postprocess(y)
46
+
47
+ def get_block_name(self) -> str:
48
+ return "html"
49
+
50
+ if __name__ == "__main__":
51
+
52
+ parser = argparse.ArgumentParser()
53
+ parser.add_argument("--share", action="store_true", default=False, help="share gradio app")
54
+ parser.add_argument("--port", type=int, default=7860, help="gradio server port")
55
+ parser.add_argument("--max-gen", type=int, default=1024, help="max")
56
+ opt = parser.parse_args()
57
+
58
+ app = gr.Blocks()
59
+ with app:
60
+ gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>Midi Composer</h1>")
61
+ gr.Markdown("![Visitors](https://api.visitorbadge.io/api/visitors?path=skytnt.midi-composer&style=flat)\n\n"
62
+ "Midi event transformer for music generation\n\n"
63
+ "Demo for [SkyTNT/midi-model](https://github.com/SkyTNT/midi-model)\n\n"
64
+ "[Open In Colab]"
65
+ "(https://colab.research.google.com/github/SkyTNT/midi-model/blob/main/demo.ipynb)"
66
+ " for faster running and longer generation"
67
+ )
68
+
69
+ app.queue(2).launch(server_port=opt.port, share=opt.share, inbrowser=True)