wissemkarous commited on
Commit
4f82165
1 Parent(s): 83e2663
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from tensorflow.keras.models import load_model
2
+
3
+ # Load your trained model
4
+ model = load_model('path_to_your_model.h5')
5
+ import pandas as pd
6
+
7
+ def predict_from_csv(file_path):
8
+ # Load the data
9
+ data = pd.read_csv(file_path)
10
+
11
+ # Assume your model expects data in a specific order and format
12
+ # Here we reorder the columns if necessary and handle any preprocessing like normalization
13
+ required_columns = ['CAN ID', 'RTR', 'DLC', 'Data1', 'Data2', 'Data3', 'Data4', 'Data5', 'Data6', 'Data7', 'Data8']
14
+ data = data[required_columns]
15
+
16
+ # Convert data to numpy array or the format your model expects
17
+ input_data = data.values
18
+
19
+ # Predict using the model
20
+ predictions = model.predict(input_data)
21
+
22
+ # Here, you could process the predictions to a more readable format if needed
23
+ return predictions
24
+
25
+ def interface_func(file_info):
26
+ # Get the path of the uploaded file
27
+ filepath = file_info["path"]
28
+ # Use the prediction function
29
+ prediction = predict_from_csv(filepath)
30
+ return prediction
31
+
32
+ iface = gr.Interface(fn=interface_func,
33
+ inputs=gr.inputs.File(label="Upload CSV"),
34
+ outputs="text",
35
+ description="Upload a CSV file with the specified columns to predict.")
36
+
37
+ iface.launch()