|
import streamlit as st |
|
import pandas as pd |
|
import matplotlib.pyplot as plt |
|
from utils.preprocessing import clean_data |
|
from utils.models import predict_umkm |
|
|
|
|
|
st.set_page_config(page_title="AI Supply Chain UMKM", layout="wide") |
|
st.title("π AI Manajemen Inventori UMKM") |
|
|
|
|
|
with st.sidebar: |
|
st.header("βοΈ Pengaturan") |
|
hari_prediksi = st.slider("Jumlah Hari Prediksi", 1, 14, 7) |
|
stok_aman = st.number_input("Stok Pengaman (Safety Stock)", min_value=0, value=10) |
|
|
|
|
|
uploaded_file = st.file_uploader( |
|
"Upload Data Historis (Format CSV)", |
|
type="csv", |
|
help="Contoh format: tanggal, demand, supply" |
|
) |
|
|
|
if uploaded_file: |
|
try: |
|
|
|
df = clean_data(uploaded_file) |
|
|
|
|
|
if not all(col in df.columns for col in ['tanggal', 'demand', 'supply']): |
|
raise ValueError("Format kolom harus: tanggal, demand, supply") |
|
|
|
|
|
st.subheader("π Tren Historis") |
|
fig, ax = plt.subplots(figsize=(12, 6)) |
|
|
|
ax.plot(df['tanggal'], df['demand'], label='Permintaan', color='#1f77b4', marker='o') |
|
ax.plot(df['tanggal'], df['supply'], label='Persediaan', color='#ff7f0e', marker='s') |
|
|
|
ax.fill_between( |
|
df['tanggal'], |
|
df['demand'], |
|
df['supply'], |
|
where=(df['supply'] > df['demand']), |
|
color='#2ca02c', alpha=0.3, label='Surplus' |
|
) |
|
ax.fill_between( |
|
df['tanggal'], |
|
df['demand'], |
|
df['supply'], |
|
where=(df['supply'] < df['demand']), |
|
color='#d62728', alpha=0.3, label='Defisit' |
|
) |
|
|
|
ax.set_xlabel("Tanggal") |
|
ax.set_ylabel("Jumlah Unit") |
|
ax.legend() |
|
ax.grid(True) |
|
st.pyplot(fig) |
|
|
|
|
|
st.subheader("π€ Rekomendasi AI") |
|
|
|
with st.spinner("Menganalisis data..."): |
|
hasil = predict_umkm( |
|
data=df, |
|
prediction_length=hari_prediksi, |
|
safety_stock=stok_aman |
|
) |
|
|
|
st.success(f"**Rekomendasi:** {hasil['rekomendasi']}") |
|
|
|
with st.expander("π Detail Analisis"): |
|
st.write(f"**Prediksi {hari_prediksi} Hari:**") |
|
st.line_chart(pd.Series(hasil['prediksi'], name='Prediksi')) |
|
st.json({ |
|
"ROI Estimasi": f"{hasil['roi']}%", |
|
"Stok Optimal": hasil['stok_optimal'], |
|
"Anomali Terdeteksi": hasil['anomali'] |
|
}) |
|
|
|
except Exception as e: |
|
st.error(f"β οΈ Error: {str(e)}") |
|
st.info("Pastikan file CSV sesuai format contoh di bawah") |
|
|
|
else: |
|
st.info(""" |
|
**Contoh Data CSV:** |
|
```csv |
|
tanggal,demand,supply |
|
2024-01-01,100,120 |
|
2024-01-02,150,130 |
|
2024-01-03,200,180 |
|
``` |
|
""") |