kodetr commited on
Commit
0d8310f
·
verified ·
1 Parent(s): 65d8797

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -12
app.py CHANGED
@@ -1,15 +1,11 @@
1
  import tensorflow as tf
2
- import gradio as gr
3
  import numpy as np
4
  import os
5
  import warnings
6
  import io
7
- import json
8
- import base64
9
  from PIL import Image
10
- import tempfile
11
  from fastapi import FastAPI, File, UploadFile, HTTPException
12
- from fastapi.responses import JSONResponse, HTMLResponse
13
  from fastapi.middleware.cors import CORSMiddleware
14
  import uvicorn
15
 
@@ -171,9 +167,13 @@ def predict_image(image):
171
 
172
 
173
  # ============================================================
174
- # 4. CREATE FASTAPI APP (optional, for API endpoints)
175
  # ============================================================
176
- app = FastAPI(title="DR & DME Detection API")
 
 
 
 
177
 
178
  app.add_middleware(
179
  CORSMiddleware,
@@ -183,8 +183,32 @@ app.add_middleware(
183
  allow_headers=["*"],
184
  )
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  @app.post("/api/predict")
187
  async def api_predict(file: UploadFile = File(...)):
 
 
 
 
 
188
  try:
189
  if not file.content_type.startswith('image/'):
190
  raise HTTPException(status_code=400, detail="File must be an image")
@@ -202,22 +226,22 @@ async def api_predict(file: UploadFile = File(...)):
202
  except Exception as e:
203
  raise HTTPException(status_code=500, detail=str(e))
204
 
205
- # Mount Gradio app
206
- app = gr.mount_gradio_app(app, path="/")
207
 
208
  # ============================================================
209
  # 5. MAIN ENTRY POINT
210
  # ============================================================
211
  if __name__ == "__main__":
212
  print("\n" + "="*60)
213
- print("🚀 DR & DME Detection System Starting...")
214
  print("="*60)
215
- print(f"📱 API Endpoint: http://localhost:7860/api/predict")
 
 
216
  print("="*60)
217
 
218
  uvicorn.run(
219
  app,
220
  host="0.0.0.0",
221
- port=7860,
222
  log_level="info"
223
  )
 
1
  import tensorflow as tf
 
2
  import numpy as np
3
  import os
4
  import warnings
5
  import io
 
 
6
  from PIL import Image
 
7
  from fastapi import FastAPI, File, UploadFile, HTTPException
8
+ from fastapi.responses import JSONResponse
9
  from fastapi.middleware.cors import CORSMiddleware
10
  import uvicorn
11
 
 
167
 
168
 
169
  # ============================================================
170
+ # 4. CREATE FASTAPI APP (API ONLY)
171
  # ============================================================
172
+ app = FastAPI(
173
+ title="DR & DME Detection API",
174
+ description="API untuk deteksi Diabetic Retinopathy (DR) dan Diabetic Macular Edema (DME) dari gambar retina",
175
+ version="1.0.0"
176
+ )
177
 
178
  app.add_middleware(
179
  CORSMiddleware,
 
183
  allow_headers=["*"],
184
  )
185
 
186
+ @app.get("/")
187
+ async def root():
188
+ return {
189
+ "message": "DR & DME Detection API",
190
+ "endpoints": {
191
+ "POST /api/predict": "Upload image for prediction",
192
+ "GET /health": "Check API health status"
193
+ },
194
+ "version": "1.0.0"
195
+ }
196
+
197
+ @app.get("/health")
198
+ async def health_check():
199
+ return {
200
+ "status": "healthy",
201
+ "model_loaded": best_model is not None,
202
+ "timestamp": np.datetime64('now').astype(str)
203
+ }
204
+
205
  @app.post("/api/predict")
206
  async def api_predict(file: UploadFile = File(...)):
207
+ """
208
+ Predict DR and DME from retinal image
209
+
210
+ - **file**: Image file (JPEG, PNG, etc.)
211
+ """
212
  try:
213
  if not file.content_type.startswith('image/'):
214
  raise HTTPException(status_code=400, detail="File must be an image")
 
226
  except Exception as e:
227
  raise HTTPException(status_code=500, detail=str(e))
228
 
 
 
229
 
230
  # ============================================================
231
  # 5. MAIN ENTRY POINT
232
  # ============================================================
233
  if __name__ == "__main__":
234
  print("\n" + "="*60)
235
+ print("🚀 DR & DME Detection API Starting...")
236
  print("="*60)
237
+ print(f"📱 Health Check: http://localhost:8000/health")
238
+ print(f"📱 API Docs: http://localhost:8000/docs")
239
+ print(f"📱 Predict: POST http://localhost:8000/api/predict")
240
  print("="*60)
241
 
242
  uvicorn.run(
243
  app,
244
  host="0.0.0.0",
245
+ port=8000, # Changed from 7860 to 8000
246
  log_level="info"
247
  )