File size: 1,169 Bytes
4b8add8
a324d35
 
 
 
 
28d4a48
4b8add8
 
 
a324d35
4b8add8
a324d35
28d4a48
a324d35
 
28d4a48
a324d35
 
 
0440734
a324d35
 
 
 
 
 
 
 
 
 
 
 
4b8add8
a324d35
 
 
0440734
4b8add8
a324d35
4b8add8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import tensorflow as tf
from tensorflow import keras
from fastapi import FastAPI
from pydantic import BaseModel
import uvicorn

# Suppress TensorFlow logging
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

# Load the model
model_path = '/content/drive/MyDrive/DoctorAi/doctor_ai_model.h5'
model = keras.models.load_model(model_path)

# Create FastAPI app
app = FastAPI()

# Define the request model
class InputData(BaseModel):
    input_data: list

# Define the prediction endpoint
@app.post('/predict')
async def predict(data: InputData):
    # Prepare input data
    input_array = tf.convert_to_tensor(data.input_data)
    
    # Check if input shape matches the model's input shape
    expected_shape = (None, 27)
    if input_array.shape[1] != expected_shape[1]:
        return {'error': f'Input data must have shape: {expected_shape}'}
    
    # Make a prediction
    prediction = model.predict(tf.expand_dims(input_array, axis=0))
    predicted_class = tf.argmax(prediction, axis=1).numpy().tolist()
    
    return {'predicted_class': predicted_class}

# Start the FastAPI server
if __name__ == '__main__':
    uvicorn.run(app, host='127.0.0.1', port=8000)