MainiSandeep1987 commited on
Commit
d06aefb
·
verified ·
1 Parent(s): 9258d5a

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. Dockerfile +13 -14
  2. app.py +58 -10
  3. requirements.txt +2 -2
Dockerfile CHANGED
@@ -1,14 +1,13 @@
1
- # FROM python:3.9-slim
2
- # WORKDIR /app
3
- # COPY . .
4
- # COPY requirements.txt .
5
- # COPY app.py .
6
- # RUN pip install --no-cache-dir --upgrade -r requirements.txt
7
- # CMD ["streamlit", "run", "app.py", "server.address=0.0.0.0", "server.port=8501"]
8
- FROM python:3.9-slim
9
- WORKDIR /app
10
- COPY requirements.txt .
11
- RUN pip install --no-cache-dir -r requirements.txt
12
- COPY app.py .
13
- CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
14
-
 
1
+ # FROM python:3.9-slim
2
+ # WORKDIR /app
3
+ # COPY . .
4
+ # COPY requirements.txt .
5
+ # COPY app.py .
6
+ # RUN pip install --no-cache-dir --upgrade -r requirements.txt
7
+ # CMD ["streamlit", "run", "app.py", "server.address=0.0.0.0", "server.port=8501"]
8
+ FROM python:3.9-slim
9
+ WORKDIR /app
10
+ COPY requirements.txt .
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+ COPY app.py .
13
+ CMD ["streamlit", "run", "app.py", "--server.port=7862", "--server.address=0.0.0.0"]
 
app.py CHANGED
@@ -46,20 +46,68 @@ customer_data = pd.DataFrame([{
46
 
47
 
48
  # Single prediction section
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  if st.button("Predict"):
50
  try:
51
- print(customer_data)
52
- response = requests.post(
 
53
  "https://MainiSandeep1987-BackEndFlaskAPITelecomChurnPrediction.hf.space/v1/customer",
54
- json=customer_data.to_dict(orient='records')[0]
55
- ) # Send data to Flask API
56
- response.raise_for_status() # Raise an error if the request fails
57
- result = response.json()
58
- churn_prediction = result["Prediction"] # Extract only the value
59
- st.write(f"Based on the information provided, the customer with ID {CustomerID} is likely to {churn_prediction}.")
60
- except requests.exceptions.RequestException as e:
61
- st.error(f"Error making prediction: {e}")
62
 
 
 
 
 
 
 
 
 
63
 
64
  # Batch Prediction
65
  st.subheader("Batch Prediction")
 
46
 
47
 
48
  # Single prediction section
49
+ # if st.button("Predict"):
50
+ # try:
51
+ # print(customer_data)
52
+ # response = requests.post(
53
+ # "https://MainiSandeep1987-BackEndFlaskAPITelecomChurnPrediction.hf.space/v1/customer",
54
+ # json=customer_data.to_dict(orient='records')[0]
55
+ # ) # Send data to Flask API
56
+ # response.raise_for_status() # Raise an error if the request fails
57
+ # result = response.json()
58
+ # churn_prediction = result["Prediction"] # Extract only the value
59
+ # st.write(f"Based on the information provided, the customer with ID {CustomerID} is likely to {churn_prediction}.")
60
+ # except requests.exceptions.RequestException as e:
61
+ # st.error(f"Error making prediction: {e}")
62
+
63
+
64
+
65
+ # Function for handling retries with exponential backoff
66
+ def make_request_with_backoff(url, payload, max_retries=5):
67
+ retry_delay = 2 # Initial retry delay (in seconds)
68
+
69
+ for attempt in range(max_retries):
70
+ try:
71
+ response = requests.post(url, json=payload)
72
+ response.raise_for_status() # Ensure successful response
73
+
74
+ return response.json() # Return data if request succeeds
75
+
76
+ except requests.exceptions.RequestException as e:
77
+ if response.status_code == 429: # Too many requests
78
+ st.warning(f"Rate limit exceeded. Retrying in {retry_delay} seconds...")
79
+ time.sleep(retry_delay) # Wait before retrying
80
+ retry_delay *= 2 # Exponential backoff (2s, 4s, 8s, etc.)
81
+ else:
82
+ st.error(f"Request failed: {e}")
83
+ return None
84
+
85
+ st.error("Max retries reached. Try again later.")
86
+ return None
87
+
88
+ # Single prediction section with retry mechanism
89
  if st.button("Predict"):
90
  try:
91
+ print(customer_data) # Display input data for debugging
92
+
93
+ result = make_request_with_backoff(
94
  "https://MainiSandeep1987-BackEndFlaskAPITelecomChurnPrediction.hf.space/v1/customer",
95
+ customer_data.to_dict(orient='records')[0]
96
+ )
97
+
98
+ if result:
99
+ churn_prediction = result.get("Prediction", "Unknown") # Safe key lookup
100
+ customer_id = customer_data.get("CustomerID", "Unknown") # Prevent undefined errors
101
+ st.write(f"Based on the information provided, the customer with ID {customer_id} is likely to {churn_prediction}.")
 
102
 
103
+ except KeyError as e:
104
+ st.error(f"Unexpected response format: Missing key {e}")
105
+ except Exception as e:
106
+ st.error(f"Unexpected error: {e}")
107
+
108
+
109
+
110
+
111
 
112
  # Batch Prediction
113
  st.subheader("Batch Prediction")
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- pandas==2.2.2
2
- requests==2.28.1
3
  streamlit==1.43.2
 
1
+ pandas==2.2.2
2
+ requests==2.28.1
3
  streamlit==1.43.2