Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,108 +1,43 @@
|
|
1 |
-
# app.py
|
2 |
-
import argparse
|
3 |
import streamlit as st
|
4 |
import os
|
5 |
-
|
6 |
-
from
|
7 |
-
|
8 |
-
# Streamlit 설정
|
9 |
-
st.set_page_config(
|
10 |
-
page_title="ACE Step Music Generator",
|
11 |
-
page_icon="🎵",
|
12 |
-
layout="wide"
|
13 |
-
)
|
14 |
-
|
15 |
-
def get_args():
|
16 |
-
"""환경변수 또는 기본값으로 설정"""
|
17 |
-
return {
|
18 |
-
'checkpoint_path': os.environ.get('CHECKPOINT_PATH'),
|
19 |
-
'device_id': int(os.environ.get('DEVICE_ID', '0')),
|
20 |
-
'bf16': os.environ.get('BF16', 'True').lower() == 'true',
|
21 |
-
'torch_compile': os.environ.get('TORCH_COMPILE', 'False').lower() == 'true'
|
22 |
-
}
|
23 |
-
|
24 |
-
@st.cache_resource
|
25 |
-
def load_model(args):
|
26 |
-
"""모델 로딩 (캐시됨)"""
|
27 |
-
os.environ["CUDA_VISIBLE_DEVICES"] = str(args['device_id'])
|
28 |
-
persistent_storage_path = "/data"
|
29 |
-
|
30 |
-
model_demo = ACEStepPipeline(
|
31 |
-
checkpoint_dir=args['checkpoint_path'],
|
32 |
-
dtype="bfloat16" if args['bf16'] else "float32",
|
33 |
-
persistent_storage_path=persistent_storage_path,
|
34 |
-
torch_compile=args['torch_compile']
|
35 |
-
)
|
36 |
-
data_sampler = DataSampler()
|
37 |
-
return model_demo, data_sampler
|
38 |
|
39 |
def main():
|
40 |
-
st.
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
|
43 |
|
44 |
try:
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
-
#
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
-
|
51 |
-
st.header("Generate Music")
|
52 |
-
|
53 |
-
# 텍스트 입력
|
54 |
-
prompt = st.text_area(
|
55 |
-
"Enter your music description:",
|
56 |
-
placeholder="Enter a description of the music you want to generate...",
|
57 |
-
height=100
|
58 |
-
)
|
59 |
-
|
60 |
-
# 생성 버튼
|
61 |
-
if st.button("Generate Music", type="primary"):
|
62 |
-
if prompt:
|
63 |
-
with st.spinner("Generating music..."):
|
64 |
-
try:
|
65 |
-
result = model_demo(prompt)
|
66 |
-
st.success("Music generated successfully!")
|
67 |
-
|
68 |
-
# 결과 표시 (result 형태에 따라 조정 필요)
|
69 |
-
if hasattr(result, 'audio'):
|
70 |
-
st.audio(result.audio)
|
71 |
-
else:
|
72 |
-
st.write(result)
|
73 |
-
|
74 |
-
except Exception as e:
|
75 |
-
st.error(f"Error generating music: {str(e)}")
|
76 |
-
else:
|
77 |
-
st.warning("Please enter a description first.")
|
78 |
|
79 |
-
with col2:
|
80 |
-
st.header("Sample Data")
|
81 |
-
|
82 |
-
if st.button("Load Sample"):
|
83 |
-
try:
|
84 |
-
sample_data = data_sampler.sample()
|
85 |
-
st.json(sample_data)
|
86 |
-
except Exception as e:
|
87 |
-
st.error(f"Error loading sample: {str(e)}")
|
88 |
-
|
89 |
-
# 파일 업로드
|
90 |
-
uploaded_file = st.file_uploader(
|
91 |
-
"Upload JSON data",
|
92 |
-
type=['json']
|
93 |
-
)
|
94 |
-
|
95 |
-
if uploaded_file:
|
96 |
-
try:
|
97 |
-
data = data_sampler.load_json(uploaded_file)
|
98 |
-
st.json(data)
|
99 |
-
except Exception as e:
|
100 |
-
st.error(f"Error loading file: {str(e)}")
|
101 |
-
|
102 |
except Exception as e:
|
103 |
-
st.error(f"Error loading
|
104 |
-
|
105 |
-
|
106 |
|
107 |
if __name__ == "__main__":
|
108 |
main()
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import os
|
3 |
+
import sys
|
4 |
+
from tempfile import NamedTemporaryFile
|
5 |
+
import traceback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def main():
|
8 |
+
st.set_page_config(
|
9 |
+
page_title="ACE Singer",
|
10 |
+
page_icon="🎵",
|
11 |
+
layout="wide"
|
12 |
+
)
|
13 |
|
14 |
+
st.title("🎵 ACE Singer")
|
15 |
|
16 |
try:
|
17 |
+
# Get the code from environment variables
|
18 |
+
code = os.environ.get("MAIN_CODE")
|
19 |
+
|
20 |
+
if not code:
|
21 |
+
st.error("⚠️ The application code wasn't found in environment variables. Please add the MAIN_CODE.")
|
22 |
+
st.info("Please set the MAIN_CODE environment variable with your application code.")
|
23 |
+
return
|
24 |
+
|
25 |
+
st.success("✅ Application code loaded successfully!")
|
26 |
|
27 |
+
# Execute the code in a controlled way
|
28 |
+
exec_globals = {
|
29 |
+
'__name__': '__main__',
|
30 |
+
'st': st,
|
31 |
+
'os': os,
|
32 |
+
'sys': sys
|
33 |
+
}
|
34 |
|
35 |
+
exec(compile(code, '<streamlit_app>', 'exec'), exec_globals)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
except Exception as e:
|
38 |
+
st.error(f"⚠️ Error loading or executing the application: {str(e)}")
|
39 |
+
with st.expander("Show detailed error"):
|
40 |
+
st.code(traceback.format_exc())
|
41 |
|
42 |
if __name__ == "__main__":
|
43 |
main()
|