Patrick Rathje
commited on
Commit
·
e5509f7
1
Parent(s):
dad4684
add example extraction
Browse files- Dockerfile +12 -3
- app.py +8 -2
- extract_examples.py +23 -0
Dockerfile
CHANGED
|
@@ -25,11 +25,17 @@ RUN npm install
|
|
| 25 |
RUN npm run build
|
| 26 |
|
| 27 |
# clone examples
|
| 28 |
-
ENV
|
| 29 |
-
RUN git clone https://github.com/motion-canvas/examples /motion-canvas/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# docs/docs and docs/api should be interesting resources
|
| 32 |
-
|
| 33 |
RUN git clone https://github.com/motion-canvas/motion-canvas.github.io /motion-canvas/docs
|
| 34 |
|
| 35 |
|
|
@@ -39,6 +45,9 @@ RUN pip install --no-cache-dir gradio[mcp] gradio_motioncanvasplayer
|
|
| 39 |
COPY . .
|
| 40 |
|
| 41 |
RUN mkdir -p /app/public
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
RUN useradd -m -u 1000 user
|
| 44 |
|
|
|
|
| 25 |
RUN npm run build
|
| 26 |
|
| 27 |
# clone examples
|
| 28 |
+
#ENV MC_EXAMPLE_PROJECTS_DIR=/motion-canvas/examples
|
| 29 |
+
#RUN git clone https://github.com/motion-canvas/examples /motion-canvas/example-projects
|
| 30 |
+
|
| 31 |
+
ENV MC_DIR=/motion-canvas/motion-canvas
|
| 32 |
+
ENV MC_DOCS_DIR=/motion-canvas/motion-canvas/packages/docs
|
| 33 |
+
RUN git clone https://github.com/motion-canvas/motion-canvas /motion-canvas/motion-canvas
|
| 34 |
+
|
| 35 |
+
ENV MC_EXAMPLE_SCENES_DIR=/motion-canvas/motion-canvas/packages/examples/src/scenes
|
| 36 |
|
| 37 |
# docs/docs and docs/api should be interesting resources
|
| 38 |
+
|
| 39 |
RUN git clone https://github.com/motion-canvas/motion-canvas.github.io /motion-canvas/docs
|
| 40 |
|
| 41 |
|
|
|
|
| 45 |
COPY . .
|
| 46 |
|
| 47 |
RUN mkdir -p /app/public
|
| 48 |
+
ENV MC_EXAMPLES_MD_FILE=/app/public/examples.md
|
| 49 |
+
RUN python extract_examples.py $MC_EXAMPLES_MD_FILE
|
| 50 |
+
|
| 51 |
|
| 52 |
RUN useradd -m -u 1000 user
|
| 53 |
|
app.py
CHANGED
|
@@ -69,7 +69,7 @@ def build_project(code):
|
|
| 69 |
# Check for errors
|
| 70 |
stderr_output = process.stderr.read()
|
| 71 |
if stderr_output:
|
| 72 |
-
acc_logs += "\n" +
|
| 73 |
|
| 74 |
# check if the build was successful
|
| 75 |
if process.returncode != 0:
|
|
@@ -144,7 +144,13 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
| 144 |
for ex in EXAMPLES:
|
| 145 |
btn = gr.Button("Load Example: " + ex["name"], variant="secondary")
|
| 146 |
btn.click(partial(load_example, ex), outputs=[player, code, logs], api_name=False)
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
submit.click(build_project, inputs=[code], outputs=[player, logs], api_name="build")
|
| 149 |
|
| 150 |
if __name__ == "__main__":
|
|
|
|
| 69 |
# Check for errors
|
| 70 |
stderr_output = process.stderr.read()
|
| 71 |
if stderr_output:
|
| 72 |
+
acc_logs += "\n" + stderr_output
|
| 73 |
|
| 74 |
# check if the build was successful
|
| 75 |
if process.returncode != 0:
|
|
|
|
| 144 |
for ex in EXAMPLES:
|
| 145 |
btn = gr.Button("Load Example: " + ex["name"], variant="secondary")
|
| 146 |
btn.click(partial(load_example, ex), outputs=[player, code, logs], api_name=False)
|
| 147 |
+
|
| 148 |
+
with gr.Accordion("Show Example Scenes"):
|
| 149 |
+
example_md_content = open(os.path.join(os.path.dirname(__file__), "public", "examples.md")).read()
|
| 150 |
+
example_md = gr.Markdown(example_md_content, render=True)
|
| 151 |
+
load_example_md_btn = gr.Button("Load Example", variant="secondary", render=False)
|
| 152 |
+
load_example_md_btn.click(lambda: example_md_content, outputs=[example_md], api_name="examples")
|
| 153 |
+
|
| 154 |
submit.click(build_project, inputs=[code], outputs=[player, logs], api_name="build")
|
| 155 |
|
| 156 |
if __name__ == "__main__":
|
extract_examples.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import glob
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
assert os.environ['MC_EXAMPLE_SCENES_DIR']
|
| 6 |
+
assert os.environ['MC_EXAMPLES_MD_FILE']
|
| 7 |
+
|
| 8 |
+
with open(os.environ['MC_EXAMPLES_MD_FILE'], "w") as f:
|
| 9 |
+
|
| 10 |
+
f.write(f"# Examples for Motion Canvas Scenes in TypeScript\n")
|
| 11 |
+
|
| 12 |
+
for filepath in glob.iglob(os.environ['MC_EXAMPLE_SCENES_DIR'] + '/**/*.tsx', recursive=True):
|
| 13 |
+
name = Path(filepath).stem
|
| 14 |
+
|
| 15 |
+
f.write(f"\n\n## {name}\n")
|
| 16 |
+
|
| 17 |
+
# read the file
|
| 18 |
+
with open(filepath, 'r') as scene_file:
|
| 19 |
+
content = scene_file.read()
|
| 20 |
+
|
| 21 |
+
f.write(f"```tsx\n")
|
| 22 |
+
f.write(content)
|
| 23 |
+
f.write(f"```\n")
|