iqranaz commited on
Commit
b2b9a26
·
verified ·
1 Parent(s): 8ec5561

Upload 3 files

Browse files
Files changed (2) hide show
  1. app.py +9 -0
  2. inference/predict.py +15 -16
app.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ iface = gr.Interface(
4
+ fn="inference.predict.predict", # Assuming predict.py is in the 'inference' folder
5
+ inputs=["number", "number", "number", "number", "number", "number"],
6
+ outputs=["text"],
7
+ )
8
+
9
+ iface.launch(share=True)
inference/predict.py CHANGED
@@ -8,35 +8,34 @@ def preprocess_input(input_data):
8
  input_data['rain'] = boxcox(input_data['rain'] + 1)[0]
9
  return input_data
10
 
11
- def load_model(model_path='lgbm_model.txt'):
12
  # Load the trained LightGBM model
13
  model = lgb.Booster(model_file=model_path)
14
  return model
15
 
16
  def predict(input_data, model):
 
 
 
17
  # Make predictions using the loaded model
18
- prediction = model.predict(input_data, num_iteration=model.best_iteration)
19
  predicted_class = prediction.argmax(axis=1)
20
- return predicted_class
 
 
 
 
 
21
 
22
  if __name__ == "__main__":
23
  # Example usage
24
- input_data_path = 'path_to_input_data.xlsx' # Replace with the path to your input data file
25
- input_data = pd.read_excel(input_data_path)
26
-
27
- # Preprocess the input data
28
- preprocessed_data = preprocess_input(input_data)
29
 
30
  # Load the trained model
31
  trained_model = load_model()
32
 
33
  # Make predictions
34
- predictions = predict(preprocessed_data, trained_model)
35
-
36
- # Decode the predictions (inverse transform)
37
- label_encoder = LabelEncoder()
38
- predicted_labels = label_encoder.inverse_transform(predictions)
39
 
40
- # Display the predictions
41
- print("Predicted Labels:")
42
- print(predicted_labels)
 
8
  input_data['rain'] = boxcox(input_data['rain'] + 1)[0]
9
  return input_data
10
 
11
+ def load_model(model_path='inference/lgbm_model.txt'):
12
  # Load the trained LightGBM model
13
  model = lgb.Booster(model_file=model_path)
14
  return model
15
 
16
  def predict(input_data, model):
17
+ # Preprocess the input data
18
+ preprocessed_data = preprocess_input(pd.DataFrame([input_data]))
19
+
20
  # Make predictions using the loaded model
21
+ prediction = model.predict(preprocessed_data, num_iteration=model.best_iteration)
22
  predicted_class = prediction.argmax(axis=1)
23
+
24
+ # Decode the predicted class (inverse transform)
25
+ label_encoder = LabelEncoder()
26
+ predicted_label = label_encoder.inverse_transform(predicted_class)[0]
27
+
28
+ return predicted_label
29
 
30
  if __name__ == "__main__":
31
  # Example usage
32
+ input_data = {'wind': 10, 'rain': 5, 'humidity': 60, 'cloud': 2, 'pressure': 1015, 'avg_temp': 25}
 
 
 
 
33
 
34
  # Load the trained model
35
  trained_model = load_model()
36
 
37
  # Make predictions
38
+ prediction = predict(input_data, trained_model)
 
 
 
 
39
 
40
+ # Display the prediction
41
+ print("Predicted Label:", prediction)