Spaces:
Sleeping
Sleeping
from fastapi import FastAPI, Request | |
from transformers import pipeline | |
from pydantic import BaseModel | |
class TextQuery(BaseModel): | |
inputs: str | |
def predict(text: str): | |
model_name = "blanchefort/rubert-base-cased-sentiment-rurewiews" | |
pipe = pipeline("text-classification", model=model_name, return_all_scores=True) | |
scores = pipe(text)[0] | |
sorted_scores = sorted(scores, key=lambda x: x['score'], reverse=True) | |
return sorted_scores | |
app = FastAPI() | |
def home(request: Request, q: TextQuery): | |
return predict(q.inputs) | |