AMC / app.py
Abhi10000's picture
Create app.py
4081324 verified
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)