kebincontreras commited on
Commit
eb7596f
verified
1 Parent(s): 305780b
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import joblib
4
+ import os
5
+
6
+ # Ruta para cargar el modelo desde la carpeta 'model' dentro del directorio actual del repositorio
7
+ model_path = os.path.join('model', 'svm_model.joblib')
8
+ svm_model = joblib.load(model_path)
9
+
10
+ def predict_signature(signature):
11
+ try:
12
+ # Convertir la entrada de texto a un array numpy
13
+ signature_array = np.array([float(x.replace(',', '.').strip()) for x in signature.split("\n") if x.strip()]).reshape(1, -1)
14
+
15
+ # Predecir y devolver el resultado
16
+ prediction = svm_model.predict(signature_array)
17
+ return 'Java' if prediction[0] == 0 else 'Bangka Belitung'
18
+ except ValueError as e:
19
+ return f"Error in input: {e}"
20
+
21
+ # Crear la interfaz de Gradio
22
+ iface = gr.Interface(fn=predict_signature,
23
+ inputs=gr.Textbox(lines=2, placeholder="Paste the spectral signature here. Ensure that values are separated by newlines and decimals by commas."),
24
+ outputs="text",
25
+ title="Spectral Signature Classification",
26
+ 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.",
27
+ examples=[["0,005666667\n0,005666667\n0,005666667\n..."]])
28
+
29
+ # Ejecutar la aplicaci贸n y crear un enlace p煤blico
30
+ iface.launch(share=True)