lemonteaa commited on
Commit
6260d09
·
verified ·
1 Parent(s): 1ba4136

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -22,13 +22,16 @@ def run_manim(source_code, main_class):
22
  # Run the manim command
23
  print("Prepare to run", flush=True)
24
  command = f"manim render -ql -o {output_file_name} --media_dir {MANIM_OUT_FOLDER} {input_file_path} {main_class}"
25
- result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
26
  print("Return code:", result.returncode, flush=True)
27
  print("Output:", result.stdout, flush=True)
28
  print("Error:", result.stderr, flush=True)
29
 
30
  # Return the output video file path
31
- return output_file_path
 
 
 
32
 
33
  # Gradio Interface
34
  with gr.Blocks() as demo:
@@ -38,12 +41,14 @@ with gr.Blocks() as demo:
38
 
39
  # Output component
40
  video_output = gr.Video(label="Output Video", streaming=False, autoplay=True)
 
41
 
42
  # Button to trigger the manim command
43
  run_button = gr.Button("Run Manim")
44
 
45
  # Event listener to run the manim command and update the video output
46
- run_button.click(fn=run_manim, inputs=[source_code_input, main_class_input], outputs=video_output)
47
 
48
  if __name__ == "__main__":
 
49
  demo.launch(show_error=True)
 
22
  # Run the manim command
23
  print("Prepare to run", flush=True)
24
  command = f"manim render -ql -o {output_file_name} --media_dir {MANIM_OUT_FOLDER} {input_file_path} {main_class}"
25
+ result = subprocess.run(command, shell=True, check=False, capture_output=True, text=True)
26
  print("Return code:", result.returncode, flush=True)
27
  print("Output:", result.stdout, flush=True)
28
  print("Error:", result.stderr, flush=True)
29
 
30
  # Return the output video file path
31
+ if result.returncode == 0:
32
+ return (output_file_path, "Success")
33
+ else:
34
+ return (None, result.stderr)
35
 
36
  # Gradio Interface
37
  with gr.Blocks() as demo:
 
41
 
42
  # Output component
43
  video_output = gr.Video(label="Output Video", streaming=False, autoplay=True)
44
+ error_log_output = gr.TextArea(label="Error Log", show_copy_button=True)
45
 
46
  # Button to trigger the manim command
47
  run_button = gr.Button("Run Manim")
48
 
49
  # Event listener to run the manim command and update the video output
50
+ run_button.click(fn=run_manim, inputs=[source_code_input, main_class_input], outputs=[video_output, error_log_output])
51
 
52
  if __name__ == "__main__":
53
+ demo.queue(max_size=50)
54
  demo.launch(show_error=True)