Spaces:
Sleeping
Sleeping
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() | |