Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -15,8 +15,7 @@ os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
|
| 15 |
app = FastAPI()
|
| 16 |
|
| 17 |
|
| 18 |
-
|
| 19 |
-
model = load_model("my_model4.h5")
|
| 20 |
|
| 21 |
CLASS_NAMES = [
|
| 22 |
'Ayam Bakar', 'Ayam Geprek', 'Ayam Goreng', 'Ayam Tepung', 'Bakso', 'Bakwan',
|
|
@@ -82,7 +81,7 @@ async def hello():
|
|
| 82 |
async def predict(file: UploadFile = File(...)):
|
| 83 |
img_bytes = await file.read()
|
| 84 |
img = PIL.Image.open(io.BytesIO(img_bytes)).convert('RGB')
|
| 85 |
-
img = img.resize((
|
| 86 |
|
| 87 |
img_array = np.array(img).astype("float32") / 255.0
|
| 88 |
img_array = np.expand_dims(img_array, axis=0)
|
|
@@ -94,7 +93,7 @@ async def predict(file: UploadFile = File(...)):
|
|
| 94 |
|
| 95 |
probability = {}
|
| 96 |
for i, prob in enumerate(preds[0]):
|
| 97 |
-
probability[CLASS_NAMES[i]] = float(prob)
|
| 98 |
|
| 99 |
data_nutrisi = get_nutrition_data(predicted_label)
|
| 100 |
|
|
|
|
| 15 |
app = FastAPI()
|
| 16 |
|
| 17 |
|
| 18 |
+
model = load_model("foodnutrition.keras", compile=False)
|
|
|
|
| 19 |
|
| 20 |
CLASS_NAMES = [
|
| 21 |
'Ayam Bakar', 'Ayam Geprek', 'Ayam Goreng', 'Ayam Tepung', 'Bakso', 'Bakwan',
|
|
|
|
| 81 |
async def predict(file: UploadFile = File(...)):
|
| 82 |
img_bytes = await file.read()
|
| 83 |
img = PIL.Image.open(io.BytesIO(img_bytes)).convert('RGB')
|
| 84 |
+
img = img.resize((244, 244))
|
| 85 |
|
| 86 |
img_array = np.array(img).astype("float32") / 255.0
|
| 87 |
img_array = np.expand_dims(img_array, axis=0)
|
|
|
|
| 93 |
|
| 94 |
probability = {}
|
| 95 |
for i, prob in enumerate(preds[0]):
|
| 96 |
+
probability[CLASS_NAMES[i]] = round(float(prob) * 100, 2)
|
| 97 |
|
| 98 |
data_nutrisi = get_nutrition_data(predicted_label)
|
| 99 |
|