File size: 1,162 Bytes
0440734
a324d35
 
 
 
 
28d4a48
a324d35
 
 
28d4a48
a324d35
 
28d4a48
a324d35
 
 
0440734
a324d35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0440734
a324d35
 
 
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
import pickle
import tensorflow as tf
from tensorflow import keras
from fastapi import FastAPI
from pydantic import BaseModel
import uvicorn

# Load the model
model_path = '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))  # Expand dims to match batch size
    predicted_class = tf.argmax(prediction, axis=1).numpy().tolist()
    
    return {'predicted_class': predicted_class}

# Start the FastAPI server (this will run offline)
if __name__ == '__main__':
    uvicorn.run(app, host='127.0.0.1', port=8000)  # Use localhost for offline mode