Spaces:
Sleeping
Sleeping
Hjgugugjhuhjggg
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ from typing import Union
|
|
6 |
|
7 |
from fastapi import FastAPI, HTTPException, Response, Request, UploadFile, File
|
8 |
from fastapi.responses import StreamingResponse
|
9 |
-
from pydantic import BaseModel, ValidationError,
|
10 |
from transformers import (
|
11 |
AutoConfig,
|
12 |
AutoModelForCausalLM,
|
@@ -45,13 +45,15 @@ class GenerateRequest(BaseModel):
|
|
45 |
chunk_delay: float = 0.0
|
46 |
stop_sequences: list[str] = []
|
47 |
|
48 |
-
|
|
|
|
|
49 |
def model_name_cannot_be_empty(cls, v):
|
50 |
if not v:
|
51 |
raise ValueError("model_name cannot be empty.")
|
52 |
return v
|
53 |
|
54 |
-
@
|
55 |
def task_type_must_be_valid(cls, v):
|
56 |
valid_types = ["text-to-text", "text-to-image", "text-to-speech", "text-to-video"]
|
57 |
if v not in valid_types:
|
|
|
6 |
|
7 |
from fastapi import FastAPI, HTTPException, Response, Request, UploadFile, File
|
8 |
from fastapi.responses import StreamingResponse
|
9 |
+
from pydantic import BaseModel, ValidationError, field_validator
|
10 |
from transformers import (
|
11 |
AutoConfig,
|
12 |
AutoModelForCausalLM,
|
|
|
45 |
chunk_delay: float = 0.0
|
46 |
stop_sequences: list[str] = []
|
47 |
|
48 |
+
model_config = {"protected_namespaces": ()}
|
49 |
+
|
50 |
+
@field_validator("model_name")
|
51 |
def model_name_cannot_be_empty(cls, v):
|
52 |
if not v:
|
53 |
raise ValueError("model_name cannot be empty.")
|
54 |
return v
|
55 |
|
56 |
+
@field_validator("task_type")
|
57 |
def task_type_must_be_valid(cls, v):
|
58 |
valid_types = ["text-to-text", "text-to-image", "text-to-speech", "text-to-video"]
|
59 |
if v not in valid_types:
|