CoolFace
Apppublic

blong12/API_Arduino_video_stream

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
base_model.py71 linesDownload Raw Back to app
1from pydantic import BaseModel2from typing import List, Optional3import uuid4 5class DataResponse(BaseModel):6    status: Optional[str]7    author: Optional[str]8    data: Optional[dict]9    message: Optional[str]10 11 12class VideoData(BaseModel):13    filename: str14    size: int15    content_type: str16    video_id: str17    upload_data: dict18 19    @classmethod20    def from_file(cls, video_file):21        frames = None22        animation_width = None23        animation_height = None24        frame_data = []25 26        def read_file():27            return video_file.file.read()28 29        def process_file_data(data):30            nonlocal frames, animation_width, animation_height, frame_data31            for line in data.splitlines():32                line = line.decode('utf-8-sig').strip()33                if "frames" in line:34                    frames = int(line.split("=")[1].strip("; "))35                elif "animation_width" in line:36                    animation_width = int(line.split("=")[1].strip("; "))37                elif "animation_height" in line:38                    animation_height = int(line.split("=")[1].strip("; "))39                elif "Frame" in line:40                    frame_data = line.split("=")[1].replace("{{", '').rstrip(";}}").split('},{')41                    frame_data = [[str(value).lstrip() for value in element.split(',')] for element in frame_data]42 43        def create_video_data():44            data = read_file()45            process_file_data(data)46            return cls(47                filename=video_file.filename,48                size=video_file.size,49                content_type=video_file.content_type,50                video_id=str(uuid.uuid4()),51                upload_data={52                    "Frames": frames,53                    "Width": animation_width,54                    "Height": animation_height,55                    "Frame": frame_data56                }57            )58        return create_video_data()59 60 61    def to_dict(self):62        return {63            "file": {64                "filename": self.filename,65                "size": self.size,66                "content_type": self.content_type67            },68            "video_id": self.video_id,69            "upload_data": self.upload_data70        }71