adityasharma0511 commited on
Commit
bd4c142
·
verified ·
1 Parent(s): c287437

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py CHANGED
@@ -41,3 +41,42 @@ if st.button("Predict"):
41
  prediction = (prediction_proba >= classification_threshold).astype(int)
42
  result = "Fali" if prediction == 1 else "Not Fail"
43
  st.write(f"Based on the information provided, the engine is likely to {result}.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  prediction = (prediction_proba >= classification_threshold).astype(int)
42
  result = "Fali" if prediction == 1 else "Not Fail"
43
  st.write(f"Based on the information provided, the engine is likely to {result}.")
44
+
45
+
46
+ # Define an endpoint for batch prediction (POST request)
47
+ def predict_store_sales_batch(csv_file):
48
+ """
49
+ This function expects a CSV file containing property details for multiple properties
50
+ and returns the predicted sales as a dictionary in the JSON response.
51
+ """
52
+
53
+ # Read the CSV file into a Pandas DataFrame
54
+ input_data = pd.read_csv(csv_file)
55
+
56
+ # Make predictions for all properties in the DataFrame (get store_saless)
57
+ predicted_sales = model.predict(input_data.drop("Engine Condition",axis=1)).tolist()
58
+
59
+ # Create a dictionary of predictions with property IDs as keys
60
+ property_ids = input_data['Engine Condition'].tolist() # Assuming 'id' is the property ID column
61
+ output_dict = dict(zip(property_ids, predicted_sales)) # Use actual prices
62
+
63
+ # Return the predictions dictionary as a JSON response
64
+ return output_dict
65
+
66
+
67
+
68
+
69
+ # Section for batch prediction
70
+ st.subheader("Batch Prediction")
71
+
72
+ # Allow users to upload a CSV file for batch prediction
73
+ uploaded_file = st.file_uploader("Upload CSV file for batch prediction", type=["csv"])
74
+
75
+
76
+ # Make batch prediction when the "Predict Batch" button is clicked
77
+ if uploaded_file is not None:
78
+ if st.button("Predict Batch"):
79
+ response = predict_store_sales_batch(uploaded_file)
80
+ predictions = response.json()
81
+ st.success("Batch predictions completed!")
82
+ st.write(predictions) # Display the predictions