-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
46 lines (35 loc) · 966 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
38
39
40
41
42
43
44
45
46
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from fastapi.responses import PlainTextResponse
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from predict import Prediction
app = FastAPI()
prediction = Prediction()
class Item(BaseModel):
name: str
description: str | None = None
price: float
tax: float | None = None
class Prompt(BaseModel):
prompt: str
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.post("/items/")
async def create_item(item: Item):
return item
@app.post("/prediction")
async def send_embedding(prompt: Prompt):
item = prediction.get_embedding(str(prompt.prompt))
data = {"prompt": str(prompt),
"embedding": str(item)}
print(data)
return data
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=7979)