-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
37 lines (29 loc) · 887 Bytes
/
main.py
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
37
# main.py
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import List
from src.metrics.calculator import MetricCalculator
app = FastAPI()
calculator = MetricCalculator()
class MetricRequest(BaseModel):
metrics: List[str]
ground_truth: str
answer: str
question: str
context: str
@app.post("/calculate_metrics")
async def calculate_metrics(request: MetricRequest):
try:
results = calculator.calculate_metrics(
request.metrics,
ground_truth=request.ground_truth,
answer=request.answer,
question=request.question,
context=request.context,
)
return results
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)