File size: 3,052 Bytes
3ce3453 1da87d6 3ce3453 1da87d6 140a9fa 3ce3453 1da87d6 140a9fa 3ce3453 1da87d6 140a9fa 1da87d6 3ce3453 1da87d6 140a9fa 1da87d6 3ce3453 1da87d6 140a9fa 1da87d6 140a9fa 1da87d6 140a9fa 1da87d6 140a9fa 1da87d6 140a9fa 1da87d6 140a9fa 1da87d6 140a9fa 1da87d6 140a9fa 1da87d6 140a9fa 1da87d6 140a9fa 1da87d6 140a9fa 1da87d6 140a9fa 1da87d6 140a9fa 1da87d6 140a9fa 1da87d6 |
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
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
# Konfigurasi tampilan
st.set_page_config(page_title="AI Supply Chain UMKM", layout="wide")
st.title("π AI Manajemen Inventori UMKM")
# Sidebar untuk parameter
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)
# Upload data
uploaded_file = st.file_uploader(
"Upload Data Historis (Format CSV)",
type="csv",
help="Contoh format: tanggal, demand, supply"
)
if uploaded_file:
try:
# ===== 1. Preprocessing =====
df = clean_data(uploaded_file)
# Validasi kolom
if not all(col in df.columns for col in ['tanggal', 'demand', 'supply']):
raise ValueError("Format kolom harus: tanggal, demand, supply")
# ===== 2. Visualisasi Data =====
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)
# ===== 3. Prediksi & Rekomendasi =====
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
```
""") |