szili2011 commited on
Commit
4b8add8
1 Parent(s): a324d35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -1,12 +1,15 @@
1
- import pickle
2
  import tensorflow as tf
3
  from tensorflow import keras
4
  from fastapi import FastAPI
5
  from pydantic import BaseModel
6
  import uvicorn
7
 
 
 
 
8
  # Load the model
9
- model_path = 'doctor_ai_model.h5'
10
  model = keras.models.load_model(model_path)
11
 
12
  # Create FastAPI app
@@ -28,11 +31,11 @@ async def predict(data: InputData):
28
  return {'error': f'Input data must have shape: {expected_shape}'}
29
 
30
  # Make a prediction
31
- prediction = model.predict(tf.expand_dims(input_array, axis=0)) # Expand dims to match batch size
32
  predicted_class = tf.argmax(prediction, axis=1).numpy().tolist()
33
 
34
  return {'predicted_class': predicted_class}
35
 
36
- # Start the FastAPI server (this will run offline)
37
  if __name__ == '__main__':
38
- uvicorn.run(app, host='127.0.0.1', port=8000) # Use localhost for offline mode
 
1
+ import os
2
  import tensorflow as tf
3
  from tensorflow import keras
4
  from fastapi import FastAPI
5
  from pydantic import BaseModel
6
  import uvicorn
7
 
8
+ # Suppress TensorFlow logging
9
+ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
10
+
11
  # Load the model
12
+ model_path = '/content/drive/MyDrive/DoctorAi/doctor_ai_model.h5'
13
  model = keras.models.load_model(model_path)
14
 
15
  # Create FastAPI app
 
31
  return {'error': f'Input data must have shape: {expected_shape}'}
32
 
33
  # Make a prediction
34
+ prediction = model.predict(tf.expand_dims(input_array, axis=0))
35
  predicted_class = tf.argmax(prediction, axis=1).numpy().tolist()
36
 
37
  return {'predicted_class': predicted_class}
38
 
39
+ # Start the FastAPI server
40
  if __name__ == '__main__':
41
+ uvicorn.run(app, host='127.0.0.1', port=8000)