Spaces:
Running
Running
Commit
Β·
1c954af
1
Parent(s):
e79b79e
feat: update
Browse files- manimator/gradio_app.py +30 -16
manimator/gradio_app.py
CHANGED
|
@@ -24,29 +24,32 @@ def process_prompt(prompt: str):
|
|
| 24 |
attempts += 1
|
| 25 |
if attempts < max_attempts:
|
| 26 |
continue
|
| 27 |
-
return
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
| 29 |
class_match = re.search(r"class (\w+)\(Scene\)", code)
|
| 30 |
if not class_match:
|
| 31 |
attempts += 1
|
| 32 |
if attempts < max_attempts:
|
| 33 |
continue
|
| 34 |
-
return None, "No Scene class found after multiple attempts"
|
| 35 |
|
| 36 |
scene_name = class_match.group(1)
|
| 37 |
scene_file = processor.save_code(code, temp_dir)
|
| 38 |
video_path = processor.render_scene(scene_file, scene_name, temp_dir)
|
| 39 |
|
| 40 |
if not video_path:
|
| 41 |
-
return None, "Failed to render animation"
|
| 42 |
|
| 43 |
-
return video_path, "Animation generated successfully!"
|
| 44 |
|
| 45 |
except Exception as e:
|
| 46 |
attempts += 1
|
| 47 |
if attempts < max_attempts:
|
| 48 |
continue
|
| 49 |
-
return None, f"Error after multiple attempts: {str(e)}"
|
| 50 |
|
| 51 |
|
| 52 |
def process_pdf(file_path: str):
|
|
@@ -65,18 +68,18 @@ def process_pdf(file_path: str):
|
|
| 65 |
|
| 66 |
def interface_fn(prompt=None, pdf_file=None):
|
| 67 |
if prompt:
|
| 68 |
-
video_path, message = process_prompt(prompt)
|
| 69 |
if video_path:
|
| 70 |
-
return video_path, message
|
| 71 |
-
return None, message
|
| 72 |
elif pdf_file:
|
| 73 |
scene_description = process_pdf(pdf_file)
|
| 74 |
if scene_description:
|
| 75 |
-
video_path, message = process_prompt(scene_description)
|
| 76 |
if video_path:
|
| 77 |
-
return video_path, message
|
| 78 |
-
return None, message
|
| 79 |
-
return None, "Please provide either a prompt or upload a PDF file"
|
| 80 |
|
| 81 |
|
| 82 |
description_md = """
|
|
@@ -88,8 +91,9 @@ This tool helps you create visualizations of complex concepts using natural lang
|
|
| 88 |
- **PDF Upload**: Upload a research paper to extract key visualizations
|
| 89 |
|
| 90 |
### Links
|
|
|
|
|
|
|
| 91 |
- [Manim Documentation](https://docs.manim.community/)
|
| 92 |
-
- [Project Repository](https://github.com/yourusername/manimator)
|
| 93 |
"""
|
| 94 |
|
| 95 |
with gr.Blocks(title="manimator") as demo:
|
|
@@ -108,6 +112,11 @@ with gr.Blocks(title="manimator") as demo:
|
|
| 108 |
# Only show output UI elements here (not in the sample tab)
|
| 109 |
with gr.Row():
|
| 110 |
video_output = gr.Video(label="Generated Animation")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
status_output = gr.Textbox(
|
| 112 |
label="Status", interactive=False, show_copy_button=True
|
| 113 |
)
|
|
@@ -115,7 +124,7 @@ with gr.Blocks(title="manimator") as demo:
|
|
| 115 |
text_button.click(
|
| 116 |
fn=interface_fn,
|
| 117 |
inputs=[text_input],
|
| 118 |
-
outputs=[video_output, status_output],
|
| 119 |
)
|
| 120 |
|
| 121 |
with gr.TabItem("π PDF Upload"):
|
|
@@ -126,6 +135,11 @@ with gr.Blocks(title="manimator") as demo:
|
|
| 126 |
# Show output UI elements here as well
|
| 127 |
with gr.Row():
|
| 128 |
pdf_video_output = gr.Video(label="Generated Animation")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
pdf_status_output = gr.Textbox(
|
| 130 |
label="Status", interactive=False, show_copy_button=True
|
| 131 |
)
|
|
@@ -133,7 +147,7 @@ with gr.Blocks(title="manimator") as demo:
|
|
| 133 |
pdf_button.click(
|
| 134 |
fn=lambda pdf: interface_fn(prompt=None, pdf_file=pdf),
|
| 135 |
inputs=[file_input],
|
| 136 |
-
outputs=[pdf_video_output, pdf_status_output],
|
| 137 |
)
|
| 138 |
|
| 139 |
with gr.TabItem("Sample Examples"):
|
|
|
|
| 24 |
attempts += 1
|
| 25 |
if attempts < max_attempts:
|
| 26 |
continue
|
| 27 |
+
return (
|
| 28 |
+
None,
|
| 29 |
+
None,
|
| 30 |
+
"No valid Manim code generated after multiple attempts",
|
| 31 |
+
)
|
| 32 |
class_match = re.search(r"class (\w+)\(Scene\)", code)
|
| 33 |
if not class_match:
|
| 34 |
attempts += 1
|
| 35 |
if attempts < max_attempts:
|
| 36 |
continue
|
| 37 |
+
return None, None, "No Scene class found after multiple attempts"
|
| 38 |
|
| 39 |
scene_name = class_match.group(1)
|
| 40 |
scene_file = processor.save_code(code, temp_dir)
|
| 41 |
video_path = processor.render_scene(scene_file, scene_name, temp_dir)
|
| 42 |
|
| 43 |
if not video_path:
|
| 44 |
+
return None, None, "Failed to render animation"
|
| 45 |
|
| 46 |
+
return video_path, code, "Animation generated successfully!"
|
| 47 |
|
| 48 |
except Exception as e:
|
| 49 |
attempts += 1
|
| 50 |
if attempts < max_attempts:
|
| 51 |
continue
|
| 52 |
+
return None, None, f"Error after multiple attempts: {str(e)}"
|
| 53 |
|
| 54 |
|
| 55 |
def process_pdf(file_path: str):
|
|
|
|
| 68 |
|
| 69 |
def interface_fn(prompt=None, pdf_file=None):
|
| 70 |
if prompt:
|
| 71 |
+
video_path, code, message = process_prompt(prompt)
|
| 72 |
if video_path:
|
| 73 |
+
return [video_path, code, message]
|
| 74 |
+
return [None, None, message]
|
| 75 |
elif pdf_file:
|
| 76 |
scene_description = process_pdf(pdf_file)
|
| 77 |
if scene_description:
|
| 78 |
+
video_path, code, message = process_prompt(scene_description)
|
| 79 |
if video_path:
|
| 80 |
+
return [video_path, code, message]
|
| 81 |
+
return [None, None, message]
|
| 82 |
+
return [None, None, "Please provide either a prompt or upload a PDF file"]
|
| 83 |
|
| 84 |
|
| 85 |
description_md = """
|
|
|
|
| 91 |
- **PDF Upload**: Upload a research paper to extract key visualizations
|
| 92 |
|
| 93 |
### Links
|
| 94 |
+
- [Website](https://manimator.hypercluster.tech/)
|
| 95 |
+
- [Project Repository](https://github.com/HyperCluster-Tech/manimator)
|
| 96 |
- [Manim Documentation](https://docs.manim.community/)
|
|
|
|
| 97 |
"""
|
| 98 |
|
| 99 |
with gr.Blocks(title="manimator") as demo:
|
|
|
|
| 112 |
# Only show output UI elements here (not in the sample tab)
|
| 113 |
with gr.Row():
|
| 114 |
video_output = gr.Video(label="Generated Animation")
|
| 115 |
+
code_output = gr.Code(
|
| 116 |
+
label="Generated Manim Code",
|
| 117 |
+
language="python",
|
| 118 |
+
interactive=False,
|
| 119 |
+
)
|
| 120 |
status_output = gr.Textbox(
|
| 121 |
label="Status", interactive=False, show_copy_button=True
|
| 122 |
)
|
|
|
|
| 124 |
text_button.click(
|
| 125 |
fn=interface_fn,
|
| 126 |
inputs=[text_input],
|
| 127 |
+
outputs=[video_output, code_output, status_output],
|
| 128 |
)
|
| 129 |
|
| 130 |
with gr.TabItem("π PDF Upload"):
|
|
|
|
| 135 |
# Show output UI elements here as well
|
| 136 |
with gr.Row():
|
| 137 |
pdf_video_output = gr.Video(label="Generated Animation")
|
| 138 |
+
pdf_code_output = gr.Code(
|
| 139 |
+
label="Generated Manim Code",
|
| 140 |
+
language="python",
|
| 141 |
+
interactive=False,
|
| 142 |
+
)
|
| 143 |
pdf_status_output = gr.Textbox(
|
| 144 |
label="Status", interactive=False, show_copy_button=True
|
| 145 |
)
|
|
|
|
| 147 |
pdf_button.click(
|
| 148 |
fn=lambda pdf: interface_fn(prompt=None, pdf_file=pdf),
|
| 149 |
inputs=[file_input],
|
| 150 |
+
outputs=[pdf_video_output, pdf_code_output, pdf_status_output],
|
| 151 |
)
|
| 152 |
|
| 153 |
with gr.TabItem("Sample Examples"):
|