Spaces:
Runtime error
Runtime error
AnishKumbhar
commited on
Commit
•
36f9fc0
1
Parent(s):
7722141
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
from fastapi import FastAPI
|
2 |
from transformers import pipeline
|
3 |
import numpy as np
|
|
|
4 |
|
5 |
app = FastAPI(docs_url="/")
|
6 |
|
@@ -12,13 +13,16 @@ def preprocess_image(image: np.ndarray):
|
|
12 |
# Return the image
|
13 |
return image
|
14 |
|
|
|
|
|
|
|
15 |
@app.post("/predict")
|
16 |
-
def predict_endpoint(image:
|
17 |
# Preprocess the image
|
18 |
-
image = preprocess_image(image)
|
19 |
|
20 |
# Create a pipeline for image classification
|
21 |
-
classifier = pipeline("
|
22 |
|
23 |
# Classify the image
|
24 |
result = classifier(image)
|
|
|
1 |
from fastapi import FastAPI
|
2 |
from transformers import pipeline
|
3 |
import numpy as np
|
4 |
+
from pydantic import BaseModel, Field
|
5 |
|
6 |
app = FastAPI(docs_url="/")
|
7 |
|
|
|
13 |
# Return the image
|
14 |
return image
|
15 |
|
16 |
+
class Image(BaseModel):
|
17 |
+
image: np.ndarray = Field(...)
|
18 |
+
|
19 |
@app.post("/predict")
|
20 |
+
def predict_endpoint(image: Image):
|
21 |
# Preprocess the image
|
22 |
+
image = preprocess_image(image.image)
|
23 |
|
24 |
# Create a pipeline for image classification
|
25 |
+
classifier = pipeline("image-classification")
|
26 |
|
27 |
# Classify the image
|
28 |
result = classifier(image)
|