AISCMS / app.py
Predator911's picture
Update app.py
b4356cf verified
Raw
History Blame Contribute Delete
4.09 kB
import streamlit as st
import requests
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from datetime import datetime
API_URL = "https://aiscms.onrender.com/api"
def main():
st.set_page_config(
page_title="Space Cargo Manager",
page_icon="🚀",
layout="wide"
)
pages = {
"Dashboard": render_dashboard,
"Item Management": render_items,
"Container Management": render_containers,
"Waste Operations": render_waste,
"Time Simulation": render_simulation,
"System Logs": render_logs
}
st.sidebar.title("Navigation")
selection = st.sidebar.radio("Go to", list(pages.keys()))
pages[selection]()
def render_dashboard():
st.header("Mission Dashboard 🛰️")
# Real-time metrics
metrics = requests.get(f"{API_URL}/metrics/usage").json()
containers = requests.get(f"{API_URL}/containers").json()
cols = st.columns(4)
cols[0].metric("Total Items", metrics.get("totalItems", 0))
cols[1].metric("Active Containers", len(containers.get("containers", [])))
cols[2].metric("Storage Utilization", f"{metrics.get('utilization', 0)}%")
cols[3].metric("Waste Items", metrics.get("wasteCount", 0))
# Visualization
col1, col2 = st.columns(2)
with col1:
df = pd.DataFrame(metrics.get("priorityDistribution", []))
fig = px.pie(df, names="priority", values="count", title="Priority Distribution")
st.plotly_chart(fig)
with col2:
df = pd.DataFrame(containers.get("containers", []))
fig = px.bar(df, x="zone", y="utilization", title="Zone Utilization")
st.plotly_chart(fig)
def render_items():
st.header("Item Management 📦")
tab1, tab2, tab3 = st.tabs(["Add New", "Search", "Import"])
with tab1:
with st.form("add_item"):
item_id = st.text_input("Item ID*")
name = st.text_input("Name*")
priority = st.slider("Priority*", 1, 100, 50)
zone = st.selectbox("Preferred Zone*", ["Crew", "Lab", "Medical", "Storage"])
if st.form_submit_button("Add Item"):
response = requests.post(f"{API_URL}/items", json={
"itemId": item_id,
"name": name,
"priority": priority,
"preferredZone": zone
})
if response.json().get("success"):
st.success("Item added successfully!")
with tab2:
search_term = st.text_input("Enter Item ID or Name")
if st.button("Search"):
result = requests.get(f"{API_URL}/search", params={"itemId": search_term}).json()
if result.get("found"):
item = result["item"]
st.subheader(item["name"])
st.write(f"**Container:** {item.get('containerId', 'Unknown')}")
st.write(f"**Position:** {item.get('position', {}).get('start', {})} to {item.get('position', {}).get('end', {})}")
def render_waste():
st.header("Waste Management ♻️")
tab1, tab2 = st.tabs(["Current Waste", "Return Planning"])
with tab1:
waste = requests.get(f"{API_URL}/waste/identify").json()
if waste:
df = pd.DataFrame(waste["wasteItems"])
st.dataframe(df)
else:
st.info("No waste items identified")
with tab2:
with st.form("return_plan"):
max_weight = st.number_input("Max Return Weight (kg)", 1, 1000, 100)
if st.form_submit_button("Generate Plan"):
plan = requests.post(f"{API_URL}/waste/return-plan", json={"maxWeight": max_weight}).json()
if plan.get("success"):
st.subheader("Return Manifest")
st.write(f"Total Weight: {plan['totalWeight']} kg")
st.write(f"Total Volume: {plan['totalVolume']} m³")
st.dataframe(pd.DataFrame(plan["returnItems"]))
if __name__ == "__main__":
main()