AjaykumarPilla commited on
Commit
8928638
·
verified ·
1 Parent(s): 64c5682

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -60
app.py CHANGED
@@ -10,61 +10,54 @@ from reportlab.lib.styles import getSampleStyleSheet
10
  from reportlab.lib.units import inch
11
  from io import BytesIO
12
  import base64
13
- from fastapi import FastAPI, HTTPException
14
- from pydantic import BaseModel
15
- import uvicorn
16
- import nest_asyncio
17
-
18
- # Apply nest_asyncio to allow FastAPI in Streamlit's event loop
19
- nest_asyncio.apply()
20
-
21
- # FastAPI app for API endpoints
22
- app = FastAPI()
23
-
24
- # Pydantic model for input validation
25
- class ProjectInput(BaseModel):
26
- project_name: str
27
- phase: str
28
- task: str
29
- current_progress: float
30
- task_expected_duration: int
31
- task_actual_duration: int
32
- workforce_gap: float
33
- workforce_skill_level: str
34
- workforce_shift_hours: int
35
- weather_impact_score: int
36
- weather_forecast_date: str
37
-
38
- # API endpoint for prediction
39
- @app.post("/predict")
40
- async def predict(project_input: ProjectInput):
41
- input_data = project_input.dict()
42
- input_data["weather_condition"] = get_weather_condition(input_data["weather_impact_score"])
43
-
44
- # Validate inputs
45
- error = validate_inputs(input_data)
46
- if error:
47
- raise HTTPException(status_code=400, detail=error)
48
-
49
- # Get prediction
50
- prediction = predict_delay(input_data)
51
-
52
- if "error" in prediction:
53
- raise HTTPException(status_code=500, detail=prediction["error"])
54
-
55
- # Generate heatmap
56
- fig = generate_heatmap(prediction['delay_probability'], f"{input_data['phase']}: {input_data['task']}")
57
-
58
- # Generate PDF
59
- pdf_buffer = generate_pdf(input_data, prediction, fig)
60
- pdf_base64 = base64.b64encode(pdf_buffer.getvalue()).decode('utf-8')
61
- plt.close(fig)
62
-
63
- # Return prediction and PDF
64
- return {
65
- "prediction": prediction,
66
- "pdf_base64": pdf_base64
67
- }
68
 
69
  # Streamlit app configuration
70
  st.set_page_config(page_title="Delay 🚀", layout="wide")
@@ -115,8 +108,6 @@ def generate_pdf(input_data, prediction, heatmap_fig):
115
  f"Task Expected Duration: {input_data['task_expected_duration']} days",
116
  f"Task Actual Duration: {input_data['task_actual_duration']} days",
117
  f"Workforce Gap: {input_data['workforce_gap']}%",
118
- f"Workforce Skill Level: {input_data['workforce_skill_level']}",
119
- f"Workforce Shift Hours: {input_data['workforce_shift_hours']}",
120
  f"Weather Impact Score: {input_data['weather_impact_score']}",
121
  f"Weather Condition: {input_data['weather_condition']}",
122
  f"Weather Forecast Date: {input_data['weather_forecast_date']}"
@@ -228,6 +219,6 @@ if submit_button:
228
  st.session_state.prediction = prediction
229
  st.session_state.input_data = input_data
230
 
231
- # Run FastAPI server in the background
232
- if __name__ == "__main__":
233
- uvicorn.run(app, host="0.0.0.0", port=8000, log_level="error")
 
10
  from reportlab.lib.units import inch
11
  from io import BytesIO
12
  import base64
13
+ # Removed FastAPI-related imports
14
+ # from fastapi import FastAPI, HTTPException
15
+ # from pydantic import BaseModel
16
+ # import uvicorn
17
+ # import nest_asyncio
18
+
19
+ # Commented out nest_asyncio and FastAPI setup
20
+ # nest_asyncio.apply()
21
+ # app = FastAPI()
22
+
23
+ # Commented out Pydantic model and API endpoint
24
+ # class ProjectInput(BaseModel):
25
+ # project_name: str
26
+ # phase: str
27
+ # task: str
28
+ # current_progress: float
29
+ # task_expected_duration: int
30
+ # task_actual_duration: int
31
+ # workforce_gap: float
32
+ # workforce_skill_level: str
33
+ # workforce_shift_hours: int
34
+ # weather_impact_score: int
35
+ # weather_forecast_date: str
36
+
37
+ # @app.post("/predict")
38
+ # async def predict(project_input: ProjectInput):
39
+ # input_data = project_input.dict()
40
+ # input_data["weather_condition"] = get_weather_condition(input_data["weather_impact_score"])
41
+ #
42
+ # error = validate_inputs(input_data)
43
+ # if error:
44
+ # raise HTTPException(status_code=400, detail=error)
45
+ #
46
+ # prediction = predict_delay(input_data)
47
+ #
48
+ # if "error" in prediction:
49
+ # raise HTTPException(status_code=500, detail=prediction["error"])
50
+ #
51
+ # fig = generate_heatmap(prediction['delay_probability'], f"{input_data['phase']}: {input_data['task']}")
52
+ #
53
+ # pdf_buffer = generate_pdf(input_data, prediction, fig)
54
+ # pdf_base64 = base64.b64encode(pdf_buffer.getvalue()).decode('utf-8')
55
+ # plt.close(fig)
56
+ #
57
+ # return {
58
+ # "prediction": prediction,
59
+ # "pdf_base64": pdf_base64
60
+ # }
 
 
 
 
 
 
 
61
 
62
  # Streamlit app configuration
63
  st.set_page_config(page_title="Delay 🚀", layout="wide")
 
108
  f"Task Expected Duration: {input_data['task_expected_duration']} days",
109
  f"Task Actual Duration: {input_data['task_actual_duration']} days",
110
  f"Workforce Gap: {input_data['workforce_gap']}%",
 
 
111
  f"Weather Impact Score: {input_data['weather_impact_score']}",
112
  f"Weather Condition: {input_data['weather_condition']}",
113
  f"Weather Forecast Date: {input_data['weather_forecast_date']}"
 
219
  st.session_state.prediction = prediction
220
  st.session_state.input_data = input_data
221
 
222
+ # Commented out FastAPI server startup
223
+ # if __name__ == "__main__":
224
+ # uvicorn.run(app, host="0.0.0.0", port=8000, log_level="error")