ArsanForEver commited on
Commit
1f4c923
·
verified ·
1 Parent(s): 19bedfe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -41
app.py CHANGED
@@ -1,48 +1,11 @@
1
- from fastapi import FastAPI, UploadFile, File
2
- import tensorflow as tf
3
- import numpy as np
4
- from PIL import Image
5
- import io
6
- import uvicorn
7
 
8
  app = FastAPI()
9
 
10
- # Load model Keras
11
- model = tf.keras.models.load_model("lontara_model_finetuning.keras")
12
-
13
- # Label kelas sesuai model
14
- labels = [
15
- "Tu", "He", "We", "No", "Mu", "Bu", "Ji", "Jo", "I", "Nro", "Cu", "Na", "Bo", "Yi", "Se", "Nyi",
16
- "So", "Wa", "Ko", "Ge", "E", "Yo", "Ngu", "Ra", "Wo", "Ta", "Pe", "Nra", "Da", "Ci", "Lo", "Nci",
17
- "U", "Ro", "Mo", "Nre", "Du", "Be", "Mpu", "Hu", "Ne", "Nyo", "Ncu", "Su", "Ju", "Gu", "Nu", "Di",
18
- "Nri", "Gi", "Co", "Nca", "Ri", "Si", "Ja", "Bi", "Ke", "Wu", "Nki", "Te", "Go", "Ya", "Nku", "Pu",
19
- "Nka", "Ba", "Mpe", "A", "Nya", "Me", "Nge", "Mpa", "Ma", "Mpi", "O", "Mi", "Re", "Po", "Ti", "Je",
20
- "Nco", "Pa", "Ho", "Nko", "Ce", "Li", "Nke", "Ru", "Ca", "Ke_", "Do", "Ga", "Mpo", "Nye", "Nru", "Nga",
21
- "Lu", "Pi", "Ku", "Ni", "Nce", "Le", "Ngo", "De", "Ki", "Wi", "Hi", "Ye", "Ngi", "Ka", "Nyu", "La",
22
- "Ha", "Sa"
23
- ]
24
-
25
  @app.get("/")
26
  def home():
27
  return {"message": "Aksara Lontara API is running"}
28
 
29
- @app.post("/predict")
30
- async def predict(file: UploadFile = File(...)):
31
- # Baca gambar
32
- image = Image.open(io.BytesIO(await file.read())).convert("L").resize((128, 128))
33
- image = np.array(image) / 255.0
34
- image = image.reshape(1, 128, 128, 1)
35
-
36
- # Prediksi
37
- prediction = model.predict(image)
38
- label = labels[np.argmax(prediction)]
39
-
40
- return {"prediction": label}
41
-
42
-
43
- @app.get("/endpoints")
44
- def get_endpoints():
45
- return { "routes": [route.path for route in app.routes] }
46
-
47
- if __name__ == "__main__":
48
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
1
+ from fastapi import FastAPI
 
 
 
 
 
2
 
3
  app = FastAPI()
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  @app.get("/")
6
  def home():
7
  return {"message": "Aksara Lontara API is running"}
8
 
9
+ @app.get("/predict")
10
+ def predict():
11
+ return {"result": "Ini contoh endpoint"}