Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -7,18 +7,21 @@ import io
|
|
| 7 |
import pandas as pd
|
| 8 |
import os
|
| 9 |
|
|
|
|
| 10 |
# Matiin log kalo run di Windows doang
|
| 11 |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
| 12 |
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
| 13 |
|
| 14 |
app = FastAPI()
|
| 15 |
|
| 16 |
-
model = load_model("foodnutritio_baru.h5")
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
'
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Muat file CSV
|
| 24 |
nutrisi_csv = pd.read_csv('nutrisi_origin.csv')
|
|
@@ -73,7 +76,7 @@ async def hello():
|
|
| 73 |
async def predict(file: UploadFile = File(...)):
|
| 74 |
img_bytes = await file.read()
|
| 75 |
img = PIL.Image.open(io.BytesIO(img_bytes)).convert('RGB')
|
| 76 |
-
img = img.resize((
|
| 77 |
|
| 78 |
img_array = np.array(img).astype("float32") / 255.0
|
| 79 |
img_array = np.expand_dims(img_array, axis=0)
|
|
@@ -100,5 +103,4 @@ async def predict_text(nama_makanan: str = Form(...)):
|
|
| 100 |
"prediction": nama_makanan,
|
| 101 |
"confidence": 1.0,
|
| 102 |
"nutrisi": data_nutrisi
|
| 103 |
-
|
| 104 |
}
|
|
|
|
| 7 |
import pandas as pd
|
| 8 |
import os
|
| 9 |
|
| 10 |
+
|
| 11 |
# Matiin log kalo run di Windows doang
|
| 12 |
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
| 13 |
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
| 14 |
|
| 15 |
app = FastAPI()
|
| 16 |
|
|
|
|
| 17 |
|
| 18 |
+
model = load_model("foodnutrition.h5")
|
| 19 |
+
|
| 20 |
+
CLASS_NAMES = ['Ayam Bakar', 'Ayam Geprek', 'Ayam Goreng', 'Ayam Tepung', 'Bakso', 'Bakwan',
|
| 21 |
+
'Batagor', 'Bolu Kukus', 'Burger', 'Cap Cay', 'Chicken Katsu', 'Cilok', 'Dimsum',
|
| 22 |
+
'Donat', 'Es Teh', 'Gado-Gado', 'Jasuke', 'Jus Jeruk', 'Kikil', 'Kopi', 'Mie Ayam', 'Mie Instan',
|
| 23 |
+
'Nasi Goreng', 'Nasi Padang', 'Pecel Lele', 'Pizza', 'Random Image', 'Rendang', 'Risoles',
|
| 24 |
+
'Sate Ayam', 'Seblak', 'Siomay', 'Sop', 'Soto', 'Tahu','Telur Balado', 'Telur Dadar', 'Tempe']
|
| 25 |
|
| 26 |
# Muat file CSV
|
| 27 |
nutrisi_csv = pd.read_csv('nutrisi_origin.csv')
|
|
|
|
| 76 |
async def predict(file: UploadFile = File(...)):
|
| 77 |
img_bytes = await file.read()
|
| 78 |
img = PIL.Image.open(io.BytesIO(img_bytes)).convert('RGB')
|
| 79 |
+
img = img.resize((224, 224))
|
| 80 |
|
| 81 |
img_array = np.array(img).astype("float32") / 255.0
|
| 82 |
img_array = np.expand_dims(img_array, axis=0)
|
|
|
|
| 103 |
"prediction": nama_makanan,
|
| 104 |
"confidence": 1.0,
|
| 105 |
"nutrisi": data_nutrisi
|
|
|
|
| 106 |
}
|