Callmebowoo-22 commited on
Commit
1da87d6
·
verified ·
1 Parent(s): 261f052

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -28
app.py CHANGED
@@ -1,35 +1,96 @@
1
  import streamlit as st
2
- from utils.preprocessing import clean_data
3
- from utils.models import predict_umkm
4
  import matplotlib.pyplot as plt
 
 
5
 
6
- # Judul
 
7
  st.title("🚀 AI Supply Chain UMKM")
8
 
 
 
 
 
 
 
9
  # Upload data
10
- uploaded_file = st.file_uploader("Upload CSV", type="csv")
 
 
 
 
11
  if uploaded_file:
12
- df = clean_data(uploaded_file)
13
-
14
- # Grafik supply-demand
15
- fig, ax = plt.subplots()
16
- ax.plot(df['tanggal'], df['demand'], label='Demand', color='blue')
17
- ax.plot(df['tanggal'], df['supply'], label='Supply', color='red')
18
- ax.fill_between(df['tanggal'], df['demand'], df['supply'],
19
- where=(df['supply'] > df['demand']),
20
- color='green', alpha=0.3, label='Surplus')
21
- ax.legend()
22
- st.pyplot(fig)
23
-
24
- # Rekomendasi AI
25
- st.subheader("Rekomendasi")
26
- recommendation = predict_umkm(df)
27
- st.success(recommendation)
28
-
29
- # Parameter ROI
30
- st.subheader("Parameter Keputusan")
31
- st.json({
32
- "ROI Estimasi": "15%",
33
- "Anomali Terdeteksi": 0,
34
- "Selisih (Supply - Demand)": 20
35
- })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
 
3
  import matplotlib.pyplot as plt
4
+ from utils.models import predict_umkm
5
+ from utils.preprocessing import clean_data
6
 
7
+ # Konfigurasi tampilan
8
+ st.set_page_config(page_title="AI Supply Chain UMKM", layout="wide")
9
  st.title("🚀 AI Supply Chain UMKM")
10
 
11
+ # Sidebar untuk parameter
12
+ with st.sidebar:
13
+ st.header("Pengaturan Model")
14
+ prediction_days = st.slider("Jumlah Hari Prediksi", 1, 30, 7)
15
+ confidence_level = st.slider("Tingkat Kepercayaan (%)", 70, 95, 85)
16
+
17
  # Upload data
18
+ uploaded_file = st.file_uploader(
19
+ "Upload Data CSV (Format: tanggal, demand, supply)",
20
+ type="csv"
21
+ )
22
+
23
  if uploaded_file:
24
+ try:
25
+ # Preprocessing data
26
+ df = clean_data(uploaded_file)
27
+
28
+ # Pastikan kolom ada
29
+ if not all(col in df.columns for col in ['tanggal', 'demand', 'supply']):
30
+ raise ValueError("Format kolom harus: tanggal, demand, supply")
31
+
32
+ # ===== 1. Tampilkan Grafik =====
33
+ st.subheader("Grafik Supply vs Demand")
34
+ fig, ax = plt.subplots(figsize=(12, 6))
35
+
36
+ ax.plot(df['tanggal'], df['demand'], label='Demand', color='blue', marker='o')
37
+ ax.plot(df['tanggal'], df['supply'], label='Supply', color='red', marker='s')
38
+
39
+ ax.fill_between(
40
+ df['tanggal'],
41
+ df['demand'],
42
+ df['supply'],
43
+ where=(df['supply'] > df['demand']),
44
+ color='green', alpha=0.3, label='Surplus'
45
+ )
46
+ ax.fill_between(
47
+ df['tanggal'],
48
+ df['demand'],
49
+ df['supply'],
50
+ where=(df['supply'] < df['demand']),
51
+ color='red', alpha=0.3, label='Defisit'
52
+ )
53
+
54
+ ax.set_xlabel("Tanggal")
55
+ ax.set_ylabel("Jumlah")
56
+ ax.legend()
57
+ ax.grid(True)
58
+ st.pyplot(fig)
59
+
60
+ # ===== 2. Prediksi dengan AI =====
61
+ st.subheader("Rekomendasi AI")
62
+
63
+ with st.spinner("Menganalisis data..."):
64
+ # Prediksi menggunakan GRANITE-TTM + Chronos-T5
65
+ recommendation = predict_umkm(
66
+ df,
67
+ prediction_length=prediction_days,
68
+ confidence=confidence_level/100
69
+ )
70
+
71
+ # Tampilkan hasil
72
+ st.success(recommendation['text'])
73
+
74
+ # Detail teknis
75
+ with st.expander("Detail Prediksi"):
76
+ st.json({
77
+ "prediksi_demand": recommendation['predictions'],
78
+ "roi_estimasi": f"{recommendation['roi']*100:.1f}%",
79
+ "confidence_score": recommendation['confidence']
80
+ })
81
+
82
+ except Exception as e:
83
+ st.error(f"⚠️ Error: {str(e)}")
84
+ st.info("Pastikan data berformat:\n- Kolom: tanggal, demand, supply\n- Minimal 30 data historis")
85
+
86
+ # Contoh data default jika tidak ada upload
87
+ else:
88
+ st.info("""
89
+ **Contoh Format CSV:**
90
+ ```
91
+ tanggal,demand,supply
92
+ 2024-01-01,100,120
93
+ 2024-01-02,150,130
94
+ 2024-01-03,200,180
95
+ ```
96
+ """)