Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import joblib | |
| # Load the trained model | |
| model = joblib.load("model.pkl") # Ensure the filename matches exactly | |
| # Define a function to make predictions | |
| def predict(input_data): | |
| try: | |
| input_data = [float(i) for i in input_data.split(',')] # Convert input string to a list of numbers | |
| prediction = model.predict([input_data]) # Make prediction | |
| return str(prediction[0]) # Convert output to string | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| # Create Gradio API | |
| interface = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Textbox(placeholder="Enter comma-separated numbers (e.g., 1.5, 2.3, 3.1)"), | |
| outputs="text" | |
| ) | |
| # Launch the API | |
| interface.launch() | |