|
from fastapi import FastAPI |
|
from pydantic import BaseModel |
|
from transformers import pipeline |
|
|
|
|
|
app = FastAPI() |
|
|
|
|
|
sentiment_model = pipeline("text-classification", model="wajidlinux99/gibberish-text-detector") |
|
|
|
|
|
class TextRequest(BaseModel): |
|
text: str |
|
|
|
|
|
@app.post("/predict") |
|
async def predict(request: TextRequest): |
|
result = sentiment_model(request.text) |
|
|
|
for item in result: |
|
if item["label"] == "clean": |
|
item["score"] = 1 - item["score"] |
|
return {"result": result} |
|
|
|
if __name__ == "__main__": |
|
import uvicorn |
|
uvicorn.run(app, host="0.0.0.0", port=7860) |