Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
-
|
12 |
-
from sklearn.datasets import load_iris
|
13 |
-
from sklearn.model_selection import train_test_split
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
|
18 |
-
y = data.target
|
19 |
-
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
20 |
|
21 |
-
#
|
22 |
-
|
23 |
-
model
|
|
|
|
|
24 |
|
25 |
-
#
|
26 |
-
|
27 |
-
dump(model, model_filename)
|
28 |
|
29 |
-
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from sklearn.datasets import load_iris
|
3 |
+
from sklearn.model_selection import train_test_split
|
4 |
+
from sklearn.linear_model import LogisticRegression
|
5 |
+
from joblib import dump
|
6 |
import os
|
7 |
|
8 |
+
def train_model():
|
9 |
+
# Carregar e dividir o dataset
|
10 |
+
data = load_iris()
|
11 |
+
X = data.data
|
12 |
+
y = data.target
|
13 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
14 |
|
15 |
+
# Treinando o modelo
|
16 |
+
model = LogisticRegression()
|
17 |
+
model.fit(X_train, y_train)
|
|
|
|
|
18 |
|
19 |
+
# Criar diretório para salvar o modelo
|
20 |
+
diretorio = "/mnt/data"
|
21 |
+
os.makedirs(diretorio, exist_ok=True)
|
|
|
|
|
22 |
|
23 |
+
# Salvar o modelo em /mnt/data/
|
24 |
+
model_filename = os.path.join(diretorio, "model.pkl")
|
25 |
+
dump(model, model_filename)
|
26 |
+
|
27 |
+
return f"Modelo treinado e salvo em: {model_filename}"
|
28 |
|
29 |
+
# Inicialize a interface Gradio
|
30 |
+
iface = gr.Interface(fn=train_model, inputs=[], outputs=["text"])
|
|
|
31 |
|
32 |
+
# Inicie a aplicação
|
33 |
+
iface.launch()
|