Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import os | |
| import shutil | |
| import uuid | |
| import subprocess | |
| from threading import Timer | |
| from functools import partial | |
| import time | |
| MODEL = "Qwen/Qwen2.5-Coder-32B-Instruct" | |
| if os.environ.get("HF_TOKEN"): | |
| from huggingface_hub import InferenceClient | |
| client = InferenceClient( | |
| provider="hf-inference", | |
| api_key=os.environ["HF_TOKEN"], | |
| ) | |
| def generate(promt, history, code): | |
| print(promt, history, code) | |
| completion = client.chat.completions.create( | |
| model=MODEL, | |
| messages=[ | |
| { | |
| "role": "user", | |
| "content": promt | |
| } | |
| ], | |
| ) | |
| return completion.choices[0].message | |
| else: | |
| # we try to run on a ZERO GPU space | |
| import spaces | |
| from diffusers import DiffusionPipeline | |
| pipe = DiffusionPipeline.from_pretrained(MODEL) | |
| pipe.to('cuda') | |
| def generate(promt, history, code): | |
| pass | |
| from gradio_motioncanvasplayer import MotionCanvasPlayer | |
| # Just some example project that servers as a placholder in the beginning | |
| example_project_path = "https://prathje-gradio-motioncanvasplayer.hf.space/gradio_api/file=/home/user/app/public/project-3.17.2.js" | |
| def load_example(example): | |
| return example['project_path'], example['code'], "" | |
| with gr.Blocks(theme=gr.themes.Monochrome()) as app: | |
| gr.Markdown("# Motion Canvas Agent") | |
| gr.Markdown("Leverage the power of AI and Motion Canvas to create animations using TypeScript.") | |
| player = MotionCanvasPlayer(example_project_path, auto=True, quality=0.5, width=1920, height=1080, variables="{}", render=False) | |
| code = gr.Code(value="", language="typescript", render=False) | |
| logs = gr.Textbox(value="", label="Build Logs", interactive=False, render=False) | |
| with gr.Row(): | |
| with gr.Column(): | |
| gr.Markdown("## Chat") | |
| chat = gr.ChatInterface(fn=generate, type="messages", additional_inputs=[code, logs], additional_outputs=[player, code, logs]) | |
| gr.Markdown("### TypeScript Code for Your Scene") | |
| code.render() | |
| logs.render() | |
| with gr.Column(): | |
| gr.Markdown("## Preview") | |
| player.render() | |
| if __name__ == "__main__": | |
| # Todo: In the future we could allow to use this as an MCP server, but right now, we need the preview to be available. | |
| app.launch(mcp_server=False, strict_cors=False) |