File size: 1,137 Bytes
4081324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import streamlit as st
from model_predictor import predict_next_service
from fastapi import FastAPI
import uvicorn
import nest_asyncio

# Apply nest_asyncio to allow FastAPI in Streamlit
nest_asyncio.apply()

# FastAPI app for API endpoint
app = FastAPI()

@app.post("/predict")
async def predict(data: dict):
    try:
        last_service_date = data.get("last_service_date")
        if not last_service_date:
            return {"error": "last_service_date is required"}
        predicted_date = predict_next_service(last_service_date)
        return {"predicted_next_service_date": predicted_date}
    except ValueError as e:
        return {"error": str(e)}

# Streamlit app
st.title("Predictive AMC Notifier")
equipment_id = st.text_input("Equipment ID")
last_service = st.date_input("Last Service Date")
if st.button("Predict"):
    try:
        date = predict_next_service(str(last_service))
        st.success(f"Next Predicted Service Date: {date}")
    except ValueError as e:
        st.error(f"Error: {str(e)}")

# Run FastAPI server in the background
if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8501)