File size: 972 Bytes
89be9e9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
import gradio as gr
from tensorflow import keras

# Load your Keras model
model = keras.models.load_model("model.keras")  # Ensure this file is uploaded to the Space

# Define prediction function
def predict(input_string):
    try:
        # Convert user input (comma-separated) into a NumPy array
        input_array = np.array([float(x.strip()) for x in input_string.split(',')])
        input_array = input_array.reshape(1, -1)  # Reshape for model
        prediction = model.predict(input_array)
        return prediction.tolist()
    except Exception as e:
        return f"Error: {str(e)}"

# Define Gradio interface
iface = gr.Interface(
    fn=predict,
    inputs=gr.Textbox(label="Enter comma-separated input values"),
    outputs=gr.Textbox(label="Model Prediction"),
    title="Keras Model Predictor",
    description="Enter input values (e.g., 1.2, 2.4, 3.6) for prediction"
)

# Launch the app
if __name__ == "__main__":
    iface.launch()