MainiSandeep1987 commited on
Commit
8fa2c71
·
verified ·
1 Parent(s): 362c1c1

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +43 -43
app.py CHANGED
@@ -37,14 +37,14 @@ customer_data = pd.DataFrame([{
37
 
38
 
39
  # Single prediction section
40
- # if st.button("Predict", type='primary'):
41
- # response = requests.post("https://MainiSandeep1987-BackEndFlaskAPITelecomChurnPrediction.hf.space/v1/customer", json=customer_data) # enter user name and space name before running the cell
42
- # if response.status_code == 200:
43
- # result = response.json()
44
- # churn_prediction = result["Prediction"] # Extract only the value
45
- # st.write(f"Based on the information provided, the customer with ID {CustomerID} is likely to {churn_prediction}.")
46
- # else:
47
- # st.error("Error in API request")
48
 
49
 
50
  # Single prediction section
@@ -64,48 +64,48 @@ customer_data = pd.DataFrame([{
64
 
65
 
66
 
67
- # Function for handling retries with exponential backoff
68
- def make_request_with_backoff(url, payload, max_retries=5):
69
- retry_delay = 2 # Initial retry delay (in seconds)
70
 
71
- for attempt in range(max_retries):
72
- try:
73
- response = requests.post(url, json=payload)
74
- response.raise_for_status() # Ensure successful response
75
 
76
- return response.json() # Return data if request succeeds
77
 
78
- except requests.exceptions.RequestException as e:
79
- if response.status_code == 429: # Too many requests
80
- st.warning(f"Rate limit exceeded. Retrying in {retry_delay} seconds...")
81
- time.sleep(retry_delay) # Wait before retrying
82
- retry_delay *= 2 # Exponential backoff (2s, 4s, 8s, etc.)
83
- else:
84
- st.error(f"Request failed: {e}")
85
- return None
86
 
87
- st.error("Max retries reached. Try again later.")
88
- return None
89
 
90
- # Single prediction section with retry mechanism
91
- if st.button("Predict"):
92
- try:
93
- print(customer_data) # Display input data for debugging
94
 
95
- result = make_request_with_backoff(
96
- "https://MainiSandeep1987-BackEndFlaskAPITelecomChurnPrediction.hf.space/v1/customer",
97
- customer_data.to_dict(orient='records')[0]
98
- )
99
-
100
- if result:
101
- churn_prediction = result.get("Prediction", "Unknown") # Safe key lookup
102
- customer_id = customer_data.get("CustomerID", "Unknown") # Prevent undefined errors
103
- st.write(f"Based on the information provided, the customer with ID {customer_id} is likely to {churn_prediction}.")
104
 
105
- except KeyError as e:
106
- st.error(f"Unexpected response format: Missing key {e}")
107
- except Exception as e:
108
- st.error(f"Unexpected error: {e}")
109
 
110
 
111
 
 
37
 
38
 
39
  # Single prediction section
40
+ if st.button("Predict", type='primary'):
41
+ response = requests.post("https://MainiSandeep1987-BackEndFlaskAPITelecomChurnPrediction.hf.space/v1/customer", json=customer_data) # enter user name and space name before running the cell
42
+ if response.status_code == 200:
43
+ result = response.json()
44
+ churn_prediction = result["Prediction"] # Extract only the value
45
+ st.write(f"Based on the information provided, the customer with ID {CustomerID} is likely to {churn_prediction}.")
46
+ else:
47
+ st.error("Error in API request")
48
 
49
 
50
  # Single prediction section
 
64
 
65
 
66
 
67
+ # # Function for handling retries with exponential backoff
68
+ # def make_request_with_backoff(url, payload, max_retries=5):
69
+ # retry_delay = 2 # Initial retry delay (in seconds)
70
 
71
+ # for attempt in range(max_retries):
72
+ # try:
73
+ # response = requests.post(url, json=payload)
74
+ # response.raise_for_status() # Ensure successful response
75
 
76
+ # return response.json() # Return data if request succeeds
77
 
78
+ # except requests.exceptions.RequestException as e:
79
+ # if response.status_code == 429: # Too many requests
80
+ # st.warning(f"Rate limit exceeded. Retrying in {retry_delay} seconds...")
81
+ # time.sleep(retry_delay) # Wait before retrying
82
+ # retry_delay *= 2 # Exponential backoff (2s, 4s, 8s, etc.)
83
+ # else:
84
+ # st.error(f"Request failed: {e}")
85
+ # return None
86
 
87
+ # st.error("Max retries reached. Try again later.")
88
+ # return None
89
 
90
+ # # Single prediction section with retry mechanism
91
+ # if st.button("Predict"):
92
+ # try:
93
+ # print(customer_data) # Display input data for debugging
94
 
95
+ # result = make_request_with_backoff(
96
+ # "https://MainiSandeep1987-BackEndFlaskAPITelecomChurnPrediction.hf.space/v1/customer",
97
+ # customer_data.to_dict(orient='records')[0]
98
+ # )
99
+
100
+ # if result:
101
+ # churn_prediction = result.get("Prediction", "Unknown") # Safe key lookup
102
+ # customer_id = customer_data.get("CustomerID", "Unknown") # Prevent undefined errors
103
+ # st.write(f"Based on the information provided, the customer with ID {customer_id} is likely to {churn_prediction}.")
104
 
105
+ # except KeyError as e:
106
+ # st.error(f"Unexpected response format: Missing key {e}")
107
+ # except Exception as e:
108
+ # st.error(f"Unexpected error: {e}")
109
 
110
 
111