Spaces:
No application file
No application file
Commit
•
54281e5
1
Parent(s):
53726ea
Upload 2 files
Browse files- demo.py +27 -0
- streamlit1.py +193 -0
demo.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Mebgimpor library
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
# Membuat judul
|
5 |
+
st.title('JUDUL BARU')
|
6 |
+
|
7 |
+
from PIL import Image
|
8 |
+
|
9 |
+
# Menambah subheader
|
10 |
+
st.subheader('Selamat datang di latihan Data Science Deployment')
|
11 |
+
|
12 |
+
#image = Image.open('D:\Megabagusid\Python Masterclass\ML Deployment\Streamlit\data science.jpg')
|
13 |
+
#st.image(image, use_column_width=True)
|
14 |
+
|
15 |
+
# Menulis text (ukuran kecil)
|
16 |
+
st.write('blablabla')
|
17 |
+
|
18 |
+
st.write('tulisan bawahnya')
|
19 |
+
|
20 |
+
# Membuat markdown
|
21 |
+
st.markdown('Ini adalah markdown cell seperti di jupyter notebook')
|
22 |
+
|
23 |
+
# Membuat keterangan sukses
|
24 |
+
st.success('Selamat Anda berhasil')
|
25 |
+
|
26 |
+
# Memunculkan error
|
27 |
+
st.error('Ini keterangan error')
|
streamlit1.py
ADDED
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Mebgimpor library
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
# Membuat judul
|
5 |
+
st.title('Tampilan Aplikasi Saya')
|
6 |
+
|
7 |
+
import urllib.request
|
8 |
+
from PIL import Image
|
9 |
+
|
10 |
+
# Mengambil gambar (dari link url)
|
11 |
+
urllib.request.urlretrieve('https://www.megabagus.id/wp-content/uploads/2024/07/data-science.jpg',
|
12 |
+
"gambar.jpg")
|
13 |
+
|
14 |
+
# Menambah subheader
|
15 |
+
st.subheader('Selamat datang di Data Science Deployment')
|
16 |
+
|
17 |
+
image = Image.open('gambar.jpg')
|
18 |
+
st.image(image, use_column_width=True)
|
19 |
+
|
20 |
+
# Menulis text (ukuran kecil)
|
21 |
+
st.write('menulis sebuah teks di sini')
|
22 |
+
|
23 |
+
# Membuat markdown
|
24 |
+
st.markdown('Ini adalah markdown cell seperti di jupyter notebook')
|
25 |
+
|
26 |
+
# Membuat keterangan sukses
|
27 |
+
st.success('Selamat Anda berhasil')
|
28 |
+
|
29 |
+
# Memberikan informasi
|
30 |
+
st.info('Ini adalah informasi untukmu')
|
31 |
+
|
32 |
+
# Memunculkan warning
|
33 |
+
st.warning('Ini adalah warning')
|
34 |
+
|
35 |
+
# Memunculkan error
|
36 |
+
st.error('Ini keterangan error')
|
37 |
+
|
38 |
+
# Memunculkan keterangan help
|
39 |
+
st.help(range)
|
40 |
+
|
41 |
+
st.text('---'*100)
|
42 |
+
|
43 |
+
# Mengimpor library
|
44 |
+
import numpy as np
|
45 |
+
import pandas as pd
|
46 |
+
|
47 |
+
datanp = np.random.rand(10,20)
|
48 |
+
|
49 |
+
# Memunculkan dataframe dari datanp
|
50 |
+
st.text('Berikut adalah dataframe dari Numpy')
|
51 |
+
st.dataframe(datanp)
|
52 |
+
|
53 |
+
st.text('---'*100)
|
54 |
+
|
55 |
+
# Memunculkan dataframe dari dataframe Pandas
|
56 |
+
df = pd.DataFrame(np.random.rand(10,20), columns=['col ' + str(i) for i in range(20)])
|
57 |
+
st.text('Berikut adalah dataframe dari Pandas')
|
58 |
+
st.dataframe(df.style.highlight_max(axis=1))
|
59 |
+
|
60 |
+
st.text('---'*100)
|
61 |
+
|
62 |
+
# Menampilkan grafik
|
63 |
+
st.text('Tampilan grafik')
|
64 |
+
grafik = pd.DataFrame(np.random.randn(20,3), columns=['a', 'b', 'c'])
|
65 |
+
st.line_chart(grafik)
|
66 |
+
|
67 |
+
st.text('---'*100)
|
68 |
+
|
69 |
+
# Menampilkan area chart
|
70 |
+
st.text('Tampilan Area Chart')
|
71 |
+
st.area_chart(grafik)
|
72 |
+
|
73 |
+
st.text('---'*100)
|
74 |
+
|
75 |
+
# Menampilkan bar chart
|
76 |
+
st.text('Tampilan Bar Chart')
|
77 |
+
grafik2 = pd.DataFrame(np.random.randn(50,3), columns=['a', 'b', 'c'])
|
78 |
+
st.bar_chart(grafik2)
|
79 |
+
|
80 |
+
st.text('---'*100)
|
81 |
+
|
82 |
+
# Menampilkan plot dari matplotlib
|
83 |
+
import matplotlib.pyplot as plt
|
84 |
+
arr = np.random.normal(1,1,size=100)
|
85 |
+
plt.hist(arr, bins=20)
|
86 |
+
st.set_option('deprecation.showPyplotGlobalUse', False) # untuk menghilangkan warning
|
87 |
+
st.pyplot()
|
88 |
+
|
89 |
+
st.text('---'*100)
|
90 |
+
|
91 |
+
# Menampilkan plot dari plotly
|
92 |
+
import plotly
|
93 |
+
import plotly.figure_factory as ff
|
94 |
+
|
95 |
+
# menambah Distribution Plot
|
96 |
+
x1 = np.random.randn(200) - 2
|
97 |
+
x2 = np.random.randn(200)
|
98 |
+
x3 = np.random.randn(200) + 2
|
99 |
+
|
100 |
+
hist_data = [x1,x2,x3]
|
101 |
+
group_labels = ['Group1', 'Group2', 'Group3']
|
102 |
+
|
103 |
+
st.text('Tampilan grafik Plotly (bisa diatur secara live)')
|
104 |
+
fig = ff.create_distplot(hist_data, group_labels, bin_size=[.2, .25, .5])
|
105 |
+
st.plotly_chart(fig, use_container_width=True)
|
106 |
+
|
107 |
+
st.text('---'*100)
|
108 |
+
|
109 |
+
# Menampilkan peta
|
110 |
+
df2 = pd.DataFrame(np.random.randn(100,2)/[50,50]+[10.76,47.4], columns=['lat', 'lon'])
|
111 |
+
st.map(df2)
|
112 |
+
|
113 |
+
st.text('---'*100)
|
114 |
+
|
115 |
+
# Menambah tombol
|
116 |
+
if st.button('Pencet Halo'):
|
117 |
+
st.write('Anda sudah berhasil pencet tombol Halo')
|
118 |
+
else:
|
119 |
+
st.write('Anda belum menekan Halo, silakan pencet tombol di atas')
|
120 |
+
|
121 |
+
st.text('---'*100)
|
122 |
+
|
123 |
+
# Menambah radio
|
124 |
+
hobi = st.radio('Apa hobimu?', ('membaca', 'nonton film', 'tidur'))
|
125 |
+
|
126 |
+
if hobi=='membaca':
|
127 |
+
st.write('Ternyata kamu suka membaca ya')
|
128 |
+
elif hobi=='nonton film':
|
129 |
+
st.write('Suka nonton film juga ternyata')
|
130 |
+
else:
|
131 |
+
st.write('pasti kamu sukanya tidur')
|
132 |
+
|
133 |
+
st.text('---'*100)
|
134 |
+
|
135 |
+
# Membuat tombol pilihan
|
136 |
+
pilih = st.selectbox('Bagaimana meeting tadi malam', ('semua lancar', 'agak nervous', 'tidak jelas'))
|
137 |
+
st.write('Jawaban : ',pilih)
|
138 |
+
|
139 |
+
st.text('---'*100)
|
140 |
+
|
141 |
+
# Membuat tombol pilihan (multiple choice)
|
142 |
+
pilih = st.multiselect('Bagaimana meeting tadi malam (bisa pilih lebih dari satu)', ('semua lancar', 'agak nervous', 'tidak jelas'))
|
143 |
+
st.write('Jawaban : ',pilih)
|
144 |
+
|
145 |
+
st.text('---'*100)
|
146 |
+
|
147 |
+
# Menambah slider
|
148 |
+
usia = st.slider('Berapa usiamu?', 0,100,30) #(min, max, default)
|
149 |
+
st.write('Usia = ', usia)
|
150 |
+
|
151 |
+
st.text('---'*100)
|
152 |
+
|
153 |
+
# Membuat slider dengan range
|
154 |
+
nilai = st.slider('Masukkan nilai', 0,200,(15,80)) #(min, max, default)
|
155 |
+
st.write('Nilai = ', nilai)
|
156 |
+
|
157 |
+
st.text('---'*100)
|
158 |
+
|
159 |
+
# Memasukkan nilai
|
160 |
+
angka = st.number_input('Masukkan angka',min_value=0.0, step=0.0)
|
161 |
+
st.write('Nilai Anda = ', angka)
|
162 |
+
|
163 |
+
st.text('---'*100)
|
164 |
+
|
165 |
+
# Mengupload file
|
166 |
+
upload_file = st.file_uploader('Pilih file csv', type='csv')
|
167 |
+
if upload_file is not None:
|
168 |
+
data = pd.read_csv(upload_file)
|
169 |
+
st.write(data)
|
170 |
+
st.success('File berhasil diupload')
|
171 |
+
else:
|
172 |
+
#st.error('File yang diupload kosong, silakan pilih file yang valid')
|
173 |
+
st.markdown('File yang diupload kosong, silakan pilih file yang valid')
|
174 |
+
|
175 |
+
st.text('---'*100)
|
176 |
+
|
177 |
+
# Memilih warna
|
178 |
+
warna = st.color_picker('Pilih warna :','#00f900')
|
179 |
+
st.write('Warna pilihan Anda = ', warna)
|
180 |
+
|
181 |
+
st.text('---'*100)
|
182 |
+
|
183 |
+
# Menambah sidebar
|
184 |
+
add_sidebar = st.sidebar.selectbox('Choose your analysis', ('EDA', 'model', 'prediction'))
|
185 |
+
|
186 |
+
# Memberikan progress bar
|
187 |
+
import time
|
188 |
+
with st.spinner('please wait...'):
|
189 |
+
time.sleep(5)
|
190 |
+
st.success('All files have been successfully processed')
|
191 |
+
|
192 |
+
|
193 |
+
|