Spaces:
Build error
Build error
File size: 1,541 Bytes
9c2d0b0 e0a8655 e2c5ffb de6f2f4 ad05dcc de6f2f4 58a6879 de6f2f4 e0a8655 e2c5ffb 58a6879 7f90ab6 2c13783 de6f2f4 7f90ab6 ad05dcc 660162e ad05dcc 38a00d4 b9fcfb6 de6f2f4 dc92314 660162e ad05dcc de6f2f4 ad05dcc de6f2f4 2c13783 e0a8655 2c13783 e0a8655 ad05dcc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from manim import *
import uuid
import os
from supabase import create_client, Client
import tempfile
url: str = os.environ.get("SUPABASE_URL")
key: str = os.environ.get("SUPABASE_KEY")
supabase: Client = create_client(url, key)
app = FastAPI()
class CodeData(BaseModel):
code: str # This will expect the "code" field to be a string
@app.get("/")
def greet_json():
return {"Hello": "World!"}
@app.post("/test")
def fun(data: CodeData):
try:
# Use tempfile to create a temporary file
with tempfile.NamedTemporaryFile(delete=False) as f1:
temp_file_path = f1.name
f1.write(data.code.encode()) # Make sure to encode the string
with open(temp_file_path, 'r') as f1:
code = f1.read()
exec(code)
print(os.listdir("/app"))
# Proceed with your video upload logic
with open('/app/media/videos/1080p60/DemoScene.mp4', 'rb') as f:
response = supabase.storage.from_("anim videos").upload(
file=f,
path=f"public/DemoScene_1_{str(uuid.uuid4())}.mp4",
file_options={"cache-control": "3600", "upsert": "false", "content-type": "video/mp4"},
)
except Exception as err:
# Raise an HTTPException if there's an error
raise HTTPException(status_code=500, detail=str(err))
return {"message": "Code executed successfully", "url": response} |