Repository navigation
Expand file tree
/
Copy pathStreamlit.py
More file actions
165 lines (139 loc) · 4.53 KB
/
Copy pathStreamlit.py
File metadata and controls
165 lines (139 loc) · 4.53 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import streamlit as st
import numpy as np
import datetime as dt
import time
import pandas as pd
import matplotlib.pyplot as plt
st.set_page_config(
page_title="Streamlit Demo",
page_icon="",
layout="wide" # two options wide and center
)
st.sidebar.title("Streamlit Topics")
page=st.sidebar.radio("Go to Section",
["UI & Layout",
"input Widge",
"Data Display",
"Button & File",
'Media & Status',
'Charts & Visualization'
])
if page=="UI & Layout":
st.title("UI creation & Layout")
st.header("Text Element")
st.subheader("SUbheader Example")
st.text("This is Text")
st.write("it can show text,number,table,etc.")
st.markdown("**Markdown** support_forming_")
code='''
def add(a,b):
return a+b
print(add(3,7))'''
st.code(code,language='python')
st.divider()
st.header("Colomns & Expander")
col1,col2,col3=st.columns(3)
with col1:
st.success("Colomns 1 Content")
with col2:
st.info("Column 2 Content")
with col3:
st.error("Column 3 Content")
with st.expander("Click to expand"):
st.write("Hidden Content shown here")
elif page=="input Widge":
st.title("Input Widge & Interactivity")
name=st.text_input("Enter Name")
feedback=st.text_area("Enter Feedback")
age=st.number_input("Age",1,100,18)# 1,100 is range 18 is default value
rating=st.slider("Rate session",1,10,5)# 1 to 10 is return and 5 is default value
course=st.selectbox("Select Course",['FSD-1','Fcsp-1','PS','DE'])
days=st.multiselect("Preffered Days",['Mon','Tue','Wed','Thu','Fri'])
subscribe=st.checkbox("Subscribe")
exam_date=st.date_input("Exam Date",dt.date.today())
exam_time=st.time_input("Exam Time",dt.time(10,0))
st.markdown("### Live Output")
st.write(f"Name:{name}")
st.write(f"Age:{age}")
st.write(f"Course:{course}")
st.write(f"Days:{days}")
st.write(f"Subscribe:{subscribe}")
st.write(f"Date:{exam_date}")
st.write(f"Time:{exam_time}")
elif page=="Data Display":
st.title("Displaying Data")
data={
"Student":["A","B","C"],
"Marks":[85,90,33],
"Pass":[True,True,False]
}
df=pd.DataFrame(data)
# option 1 for display file
st.subheader("Table")
st.table(df)
# option 2 for display file responsive table changeble
st.subheader("DataFrame")
st.dataframe(df)
# option 3 for display data (JSON)
st.subheader("JSON")
st.json(data)
elif page == "Button & File":
st.title("Buttons,File Upload & Download")
uploaded_file=st.file_uploader("Upload CSV",type=['csv'])
if uploaded_file:
df=pd.read_csv(uploaded_file)
st.dataframe(df)
if st.button("Generate Sample Data"):
data={
"Student":['A','B','C'],
'Marks':[88,90,33]
}
df=pd.DataFrame(data)
st.table(df)
csv=df.to_csv(index=False)
st.download_button(
'Download CSV',
csv,
'marks.csv'
)
elif page == 'Media & Status':
st.title('Media & Status Element')
st.success('Success Message')
st.warning('Warning Message')
st.error('Error Message')
st.info('info Message')
if st.button('Start Task'):
progress=st.progress(0)
with st.spinner('Processing...'):
for i in range(100):
time.sleep(0.02)
progress.progress(i+1)
st.success('Task Complated')
st.subheader("Media")
st.image('image1.webp',width='content')
st.image('https://picsum.photos/600/300',width='content')
st.audio('krish.mp3')
st.video('samplevideo.mp4')
elif page == 'Charts & Visualization':
st.title('Charts & Visulization')
x=np.arange(1,11)
y=np.random.randint(50,100,10)
st.subheader("Matplotlib Line Chart")
plt.figure()
plt.plot(x,y,marker='o')
plt.ylabel('Marks')
plt.title("Line Chart")
st.pyplot(plt)
st.subheader("Matplotlib Histogram")
plt.figure()
plt.hist(y,bins=5)
st.pyplot(plt)
st.subheader("Streamlit inbuild Graphs")
data={
'x':x,
'y':y
}
df=pd.DataFrame(data)
st.line_chart(df['y'],color='#ffaa0088')
st.bar_chart(df['y'],color='#7300ff')
st.area_chart(df['y'])