File size: 1,430 Bytes
bb7b186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)