/
Frogog
/
SE_FastAPI_Example
Обзор
Документация
Войти
/
Frogog
/
SE_FastAPI_Example
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
bugfix/refactoring
main.py
38 строк
687 B
BremeCanell
fix: removed useless print line. Changed task name for the task parameter to match the existing name in the pipeline function.
27 апр 2026, 19:53
27 апр 2026, 19:53
c7a159e
Код
Авторство
О чём код?
from typing import List from fastapi import FastAPI from transformers import pipeline from pydantic import BaseModel, Field class Item(BaseModel): text: str = Field(min_length=1, max_length=1000) class ItemsBatch(BaseModel): texts: List[str] app = FastAPI() classifier = pipeline("text-classification") @app.get("/") def root(): return {"FastApi service started!"} @app.get("/{text}") def get_params(text: str): return classifier(text) @app.post("/predict/") def predict(item: Item): return classifier(item.text) @app.post("/predict_multiple/") def predict_batch(items: ItemsBatch): results = classifier(items.texts) return {"results": results}