syeedalireza's picture
Upload folder using huggingface_hub
7a0a17c verified
"""
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()