fffiloni commited on
Commit
c94ca07
·
verified ·
1 Parent(s): b1dbec0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -25
app.py CHANGED
@@ -86,9 +86,10 @@ def infer(genre_txt_content, lyrics_txt_content):
86
  print(f"Output folder ensured at: {output_dir}")
87
 
88
 
89
- # Command and arguments with additional parameters
90
  command = [
91
- "python", "infer.py",
 
92
  "--stage1_model", "m-a-p/YuE-s1-7B-anneal-en-cot",
93
  "--stage2_model", "m-a-p/YuE-s2-1B-general",
94
  "--genre_txt", f"{genre_txt_path}",
@@ -98,38 +99,53 @@ def infer(genre_txt_content, lyrics_txt_content):
98
  "--output_dir", f"{output_dir}",
99
  "--cuda_idx", "0",
100
  "--max_new_tokens", "3000",
101
- "--disable_offload_model" # Add this to prevent GPU/CPU transfer issues
102
  ]
103
 
 
104
  try:
105
- # Run with environment variables to control CUDA
106
- env = os.environ.copy()
107
- env["CUDA_VISIBLE_DEVICES"] = "0"
108
- result = subprocess.run(
109
- command,
110
- check=True,
111
- env=env,
112
  stdout=subprocess.PIPE,
113
  stderr=subprocess.PIPE,
114
- text=True
 
 
115
  )
116
- print("Command output:", result.stdout)
117
- print("Command errors:", result.stderr)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
- # Check output files
120
- output_files = os.listdir(output_dir)
121
- if output_files:
122
- print("Output folder contents:")
123
- for file in output_files:
124
- print(f"- {file}")
125
- # TODO: Return the generated audio file path
126
- return None
 
127
  else:
128
- print("Output folder is empty.")
129
- return None
130
- except subprocess.CalledProcessError as e:
 
131
  print(f"Error occurred: {e}")
132
- print("Error output:", e.stderr)
133
  return None
134
  finally:
135
  # Clean up temporary files
 
86
  print(f"Output folder ensured at: {output_dir}")
87
 
88
 
89
+ # Command and arguments
90
  command = [
91
+ "python", "-u", # Add -u for unbuffered output
92
+ "infer.py",
93
  "--stage1_model", "m-a-p/YuE-s1-7B-anneal-en-cot",
94
  "--stage2_model", "m-a-p/YuE-s2-1B-general",
95
  "--genre_txt", f"{genre_txt_path}",
 
99
  "--output_dir", f"{output_dir}",
100
  "--cuda_idx", "0",
101
  "--max_new_tokens", "3000",
102
+ "--disable_offload_model"
103
  ]
104
 
105
+ # Execute the command
106
  try:
107
+ # Run process with real-time output
108
+ process = subprocess.Popen(
109
+ command,
 
 
 
 
110
  stdout=subprocess.PIPE,
111
  stderr=subprocess.PIPE,
112
+ text=True,
113
+ bufsize=1,
114
+ universal_newlines=True
115
  )
116
+
117
+ # Print output in real-time
118
+ while True:
119
+ output = process.stdout.readline()
120
+ error = process.stderr.readline()
121
+
122
+ if output:
123
+ print(f"Output: {output.strip()}")
124
+ if error:
125
+ print(f"Error: {error.strip()}")
126
+
127
+ # Check if process has finished
128
+ if process.poll() is not None:
129
+ break
130
+
131
+ # Get the return code
132
+ return_code = process.poll()
133
 
134
+ if return_code == 0:
135
+ print("Command executed successfully!")
136
+ output_files = os.listdir(output_dir)
137
+ if output_files:
138
+ print("Output folder contents:")
139
+ for file in output_files:
140
+ print(f"- {file}")
141
+ else:
142
+ print("Output folder is empty.")
143
  else:
144
+ print(f"Command failed with return code {return_code}")
145
+
146
+ return None
147
+ except Exception as e:
148
  print(f"Error occurred: {e}")
 
149
  return None
150
  finally:
151
  # Clean up temporary files