File size: 1,359 Bytes
7a0a17c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
"""

Minimal Streamlit UI: add tasks (id, duration), call API, show schedule.

Assumes API runs at http://localhost:8000 or set SCHEDULER_API_URL.

"""

import os
import requests
import streamlit as st

API_URL = os.environ.get("SCHEDULER_API_URL", "http://localhost:8000")


def main():
    st.title("Scheduling Optimizer")
    st.markdown("Add tasks and get an optimal single-machine schedule.")

    n = st.number_input("Number of tasks", min_value=1, max_value=20, value=3)
    tasks = []
    for i in range(int(n)):
        col1, col2 = st.columns(2)
        with col1:
            tid = st.text_input(f"Task {i+1} ID", value=f"T{i+1}", key=f"id_{i}")
        with col2:
            dur = st.number_input(f"Duration", min_value=1, value=2, key=f"dur_{i}")
        tasks.append({"id": tid, "duration": int(dur)})

    if st.button("Solve"):
        try:
            r = requests.post(f"{API_URL}/schedule", json={"tasks": tasks}, timeout=10)
            r.raise_for_status()
            data = r.json()
            st.success(f"Makespan: {data.get('makespan', 'N/A')}")
            st.json(data.get("schedule", []))
        except requests.exceptions.RequestException as e:
            st.error(f"API error: {e}. Is the server running? Start with: uvicorn main:app --port 8000")


if __name__ == "__main__":
    main()