Nick088 commited on
Commit
14c9d8c
Β·
verified Β·
1 Parent(s): a92af0b

refactor command execution

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -26,17 +26,34 @@ os.chdir("Minecraft_Skin_Generator")
26
  @spaces.GPU(duration=75)
27
  def run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_scale, model_precision_type, seed, filename, model_3d, verbose):
28
 
29
- # inference
30
  if stable_diffusion_model == '2':
31
  sd_model = "minecraft-skins"
32
  elif stable_diffusion_model == 'xl':
33
  sd_model = "minecraft-skins-sdxl"
34
 
35
- inference_command = f"python Scripts/{sd_model}.py '{prompt}' {num_inference_steps} {guidance_scale} {model_precision_type} {seed} {filename} {'--model_3d' if model_3d else ''} {'--verbose' if verbose else ''}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
- os.system(inference_command)
 
38
 
39
- # view it also as 3d model or not output
40
  if model_3d:
41
  return os.path.join(f"output_minecraft_skins/{filename}"), os.path.join(f"output_minecraft_skins/{filename}_3d_model.glb")
42
  else:
 
26
  @spaces.GPU(duration=75)
27
  def run_inference(prompt, stable_diffusion_model, num_inference_steps, guidance_scale, model_precision_type, seed, filename, model_3d, verbose):
28
 
29
+ # Determine which Stable Diffusion model to use
30
  if stable_diffusion_model == '2':
31
  sd_model = "minecraft-skins"
32
  elif stable_diffusion_model == 'xl':
33
  sd_model = "minecraft-skins-sdxl"
34
 
35
+ # Build the command as a list of argumenta
36
+ inference_command_args = [
37
+ sys.executable,
38
+ f"Scripts/{sd_model}.py",
39
+ prompt,
40
+ str(num_inference_steps),
41
+ str(guidance_scale),
42
+ model_precision_type,
43
+ str(seed),
44
+ filename
45
+ ]
46
+
47
+ # Conditionally add flags if requested
48
+ if model_3d:
49
+ inference_command_args.append('--model_3d')
50
+ if verbose:
51
+ inference_command_args.append('--verbose')
52
 
53
+ # Run the command using subprocess
54
+ subprocess.run(inference_command_args, check=True)
55
 
56
+ # Return paths to the output files
57
  if model_3d:
58
  return os.path.join(f"output_minecraft_skins/{filename}"), os.path.join(f"output_minecraft_skins/{filename}_3d_model.glb")
59
  else: