Spaces:
Runtime error
Runtime error
File size: 906 Bytes
00933b9 |
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 |
from typing import List
from fastapi import FastAPI, Request
from fastapi.responses import RedirectResponse
from pydantic import BaseModel
from similarity import get_similarity_batched, get_bleu, get_chrf
app = FastAPI(
title="Sentence similarity API",
description="Check Sentences similarities.",
version="1.0"
)
class Texts(BaseModel):
texts1: List[str]
texts2: List[str]
@app.get("/")
def home():
#return {"mensagem": "Bem-vindo à API!"}
return RedirectResponse(url="/docs")
@app.post('/api/similarity')
def get_sim(texts: Texts):
result = []
sim = get_similarity_batched(texts.texts1, texts.texts2)
for i in range(0, len(texts.texts1)):
result.append({
"bleu": get_bleu(texts.texts1[i], texts.texts2[i]),
"chrf": get_chrf(texts.texts1[i], texts.texts2[i]),
"similarity": sim[i]
})
return result |