Spaces:
Build error
Build error
| import gradio as gr | |
| import numpy as np | |
| import joblib | |
| import os | |
| # Ruta para cargar el modelo desde la carpeta 'model' dentro del directorio actual del repositorio | |
| model_path = os.path.join('model', 'svm_model.joblib') | |
| svm_model = joblib.load(model_path) | |
| def predict_signature(signature): | |
| try: | |
| # Convertir la entrada de texto a un array numpy | |
| signature_array = np.array([float(x.replace(',', '.').strip()) for x in signature.split("\n") if x.strip()]).reshape(1, -1) | |
| # Predecir y devolver el resultado | |
| prediction = svm_model.predict(signature_array) | |
| return 'Java' if prediction[0] == 0 else 'Bangka Belitung' | |
| except ValueError as e: | |
| return f"Error in input: {e}" | |
| # Crear la interfaz de Gradio | |
| iface = gr.Interface(fn=predict_signature, | |
| inputs=gr.Textbox(lines=2, placeholder="Paste the spectral signature here. Ensure that values are separated by newlines and decimals by commas."), | |
| outputs="text", | |
| title="Spectral Signature Classification", | |
| description="Paste the spectral signature into the text box to classify between Java and Bangka Belitung. Ensure that values are separated by newlines and decimals by commas.", | |
| examples=[["0,005666667\n0,005666667\n0,005666667\n..."]]) | |
| # Ejecutar la aplicación y crear un enlace público | |
| iface.launch(share=True) | |