Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -1,28 +1,25 @@
|
|
1 |
-
from
|
2 |
-
from models import sa_pipeline, query_index
|
3 |
-
from pydantic import BaseModel
|
4 |
|
5 |
-
|
6 |
-
question: str
|
7 |
|
8 |
-
|
9 |
-
|
|
|
10 |
|
11 |
-
|
12 |
-
text: str
|
13 |
|
14 |
-
class SentimentResponse(BaseModel):
|
15 |
-
label: str
|
16 |
-
score: float
|
17 |
|
18 |
-
app
|
|
|
|
|
19 |
|
20 |
-
@app.post('/question-answering', response_model=QAResponse)
|
21 |
-
def query(query: QARequest):
|
22 |
-
data = query.dict()
|
23 |
-
return {'answer': query_index(data['question'])}
|
24 |
|
25 |
-
@app.post(
|
26 |
-
def
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from model import model_pipeline
|
|
|
|
|
2 |
|
3 |
+
from typing import Union
|
|
|
4 |
|
5 |
+
from fastapi import FastAPI, UploadFile
|
6 |
+
import io
|
7 |
+
from PIL import Image
|
8 |
|
9 |
+
app = FastAPI()
|
|
|
10 |
|
|
|
|
|
|
|
11 |
|
12 |
+
@app.get("/")
|
13 |
+
def read_root():
|
14 |
+
return {"Hello": "World"}
|
15 |
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
@app.post("/ask")
|
18 |
+
def ask(text: str, image: UploadFile):
|
19 |
+
content = image.file.read()
|
20 |
+
|
21 |
+
image = Image.open(io.BytesIO(content))
|
22 |
+
# image = Image.open(image.file)
|
23 |
+
|
24 |
+
result = model_pipeline(text, image)
|
25 |
+
return {"answer": result}
|