Spaces:
Running
Running
File size: 4,012 Bytes
0b237ab b4929ca d1fd905 b4929ca 0b237ab d1fd905 |
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
from datetime import datetime
from typing import Annotated, Any, Generic, Literal, TypeVar
from pydantic import BaseModel, ConfigDict, Field, computed_field
from pydantic_core import PydanticCustomError
T = TypeVar("T", bound=BaseModel)
class ResponseData(BaseModel, Generic[T]):
code: int = 0
msg: str = "ok"
data: T | None = None
# --- Get Model Info ---
class GetModelInfo_QueryParams(BaseModel):
"""Parameters for model info query."""
model_id: str
revision: str | None = None
class GetModelInfo_RespData(BaseModel):
model_config = ConfigDict(extra="allow")
id: str
author: str | None = None
downloads: int | None = None
likes: int | None = None
tags: list[str] | None = None
pipeline_tag: str | None = None
sha: str | None = None
created_at: datetime | None = None
last_modified: datetime | None = None
private: bool | None = None
disabled: bool | None = None
gated: bool | None = None
# ... others
safetensors: "SafetensorsField | None" = None
# commits
commits: list["CommitInfo"] | None = None
class SafetensorsField(BaseModel):
model_config = ConfigDict(extra="allow")
parameters: dict[str, Any] | None = None
total: int | None = None
class CommitInfo(BaseModel):
model_config = ConfigDict(extra="allow")
commit_id: str
authors: list[str]
created_at: datetime
title: str
message: str
formatted_title: str | None = None
formatted_message: str | None = None
# --- Upload File Content ---
class UploadFileContent_Params(BaseModel):
path_in_repo: str
commit_message: str | None = None
model_id: str
model_sha: str = "main"
model_dtype: str
content: str
class UploadFileContent_RespData(BaseModel):
model_config = ConfigDict(extra="allow")
commit_url: str
commit_message: str
commit_description: str
oid: Annotated[str, Field(description="Commit hash id.")]
repo_url: "HfRepoUrl | None" = None
class HfRepoUrl(BaseModel):
model_config = ConfigDict(extra="allow")
endpoint: str
namespace: str
repo_name: str
repo_id: str
repo_type: Literal["model", "dataset", "space"]
url: str
# --- Community Submit ---
class CommunitySubmit_Params(BaseModel):
username: Annotated[str, Field(description='The username of the user. e.g. "Qwen"')]
# Commit info
model_id: Annotated[str, Field(description='The model id. e.g. "Qwen/Qwen2.5-3B"')]
model_sha: Annotated[
str, Field(description='The model sha or "main". e.g. "3aab1f1954e9cc14eb9509a215f9e5ca08227a9b"')
] = "main"
model_dtype: Literal[
# float types
"bfloat16",
"float32",
"float16",
"float64",
# int types
"int8",
"uint8",
"int16",
"uint15",
"int32",
"uint32",
"int64",
"uint64",
"bool",
# rare types
"complex32",
"complex64",
"complex128",
"float8_e4m3fn",
"float8_e5m2",
"float8_e4m3fnuz",
"float8_e5m2fnuz",
"float8_e8m0fnu",
"float4_e2m1fn_x2",
]
content: Annotated[str, Field(description='The content of the file in JSON format to upload.')]
weight_type: Literal["Original"] | str = "Original"
@computed_field
@property
def filename(self) -> str:
"""Filename of the file to upload."""
model_name = self.model_id.split("/")[-1]
if not model_name:
raise PydanticCustomError(
"model_id_invalid", "Model id {model_id!r} is invalid.", {"model_id": self.model_id}
)
if not self.username:
raise PydanticCustomError(
"username_invalid", "Username {username!r} is invalid.", {"username": self.username}
)
return f"{model_name}_eval_request_False_{self.model_dtype}_{self.weight_type}_{self.username}.json"
commit_message: str | None = None
|