Nestorthera commited on
Commit
1515aac
·
verified ·
1 Parent(s): f8fdedb

Upload app.py.txt

Browse files
Files changed (1) hide show
  1. app.py.txt +40 -0
app.py.txt ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import joblib
4
+
5
+ # Charger le modèle pré-entraîné
6
+ model = joblib.load('titanic_model.pkl')
7
+
8
+ def predict_survival(Pclass, Age, SibSp, Parch, Fare, Sex, Embarked):
9
+ # Prétraiter les caractéristiques
10
+ features = {
11
+ 'Pclass': [Pclass],
12
+ 'Age': [Age],
13
+ 'SibSp': [SibSp],
14
+ 'Parch': [Parch],
15
+ 'Fare': [Fare],
16
+ 'Sex': [Sex],
17
+ 'Embarked': [Embarked]
18
+ }
19
+ df = pd.DataFrame(features)
20
+ # Faire des prédictions
21
+ prediction = model.predict(df)
22
+ return "Survived" if prediction[0] == 1 else "Not Survived"
23
+
24
+ # Définir l'interface Gradio
25
+ interface = gr.Interface(
26
+ fn=predict_survival,
27
+ inputs=[
28
+ gr.inputs.Number(label="Pclass"),
29
+ gr.inputs.Number(label="Age"),
30
+ gr.inputs.Number(label="SibSp"),
31
+ gr.inputs.Number(label="Parch"),
32
+ gr.inputs.Number(label="Fare"),
33
+ gr.inputs.Textbox(label="Sex"),
34
+ gr.inputs.Textbox(label="Embarked")
35
+ ],
36
+ outputs=gr.outputs.Textbox(label="Survived")
37
+ )
38
+
39
+ # Lancer l'interface
40
+ interface.launch()