awacke1 commited on
Commit
a2c8759
Β·
1 Parent(s): d9d1929

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -94
app.py CHANGED
@@ -1,100 +1,103 @@
1
  import streamlit as st
2
  import pandas as pd
 
3
 
4
  # Magic commands
5
-
6
- st.set_page_config(page_title='Streamlit Cheat Sheet')
7
  st.set_option('deprecation.showfileUploaderEncoding', False)
8
 
9
- col1, col2, col3 = st.columns(3)
10
-
11
- col1.subheader('Magic commands')
12
- col1.code('''# Magic commands implicitly `st.write()`
13
- \'\'\' _This_ is some __Markdown__ \'\'\'
14
- a=3
15
- 'dataframe:', data
16
- ''')
17
-
18
- # Display text
19
-
20
- col1.subheader('Display text')
21
- col1.code('''
22
- st.text('Fixed width text')
23
- st.markdown('_Markdown_') # see *
24
- st.caption('Balloons. Hundreds of them...')
25
- st.latex(r\'\'\' e^{i\pi} + 1 = 0 \'\'\')
26
- st.write('Most objects') # df, err, func, keras!
27
- st.write(['st', 'is <', 3]) # see *
28
- st.title('My title')
29
- st.header('My header')
30
- st.subheader('My sub')
31
- st.code('for i in range(8): foo()')
32
- * optional kwarg unsafe_allow_html = True
33
- ''')
34
-
35
- # Display data
36
-
37
- col1.subheader('Display data')
38
- col1.code('''
39
- my_dataframe = pd.DataFrame({'column1': [1, 2, 3], 'column2': [4, 5, 6]})
40
- data = pd.DataFrame({'column1': [1, 2, 3], 'column2': [4, 5, 6]})
41
- st.dataframe(my_dataframe)
42
- st.table(data.iloc[0:10])
43
- st.json({'foo':'bar','fu':'ba'})
44
- st.metric(label="Temp", value="273 K", delta="1.2 K")
45
- ''')
46
-
47
- # Display charts
48
-
49
- col1.subheader('Display charts')
50
- col1.code('''
51
- data = pd.DataFrame({'x': [1, 2, 3], 'y': [4, 5, 6]})
52
- fig, ax = plt.subplots()
53
- ax.plot(data['x'], data['y'])
54
- st.line_chart(data)
55
- st.area_chart(data)
56
- st.bar_chart(data)
57
- st.pyplot(fig)
58
- st.altair_chart(data)
59
- st.vega_lite_chart(data)
60
- st.plotly_chart(data)
61
- st.bokeh_chart(data)
62
- st.pydeck_chart(data)
63
- st.deck_gl_chart(data)
64
- st.graphviz_chart(data)
65
- st.map(data)
66
- ''')
67
-
68
- # Display media
69
-
70
- col1.subheader('Display media')
71
- col1.code('''
72
- st.image('./header.png')
73
- st.audio(data)
74
- st.video(data)
75
- ''')
76
-
77
- # Display interactive widgets
78
-
79
- col2.subheader('Display interactive widgets')
80
- col2.code('''
81
- st.button('Hit me')
82
- st.download_button('On the dl', data)
83
- st.checkbox('Check me out')
84
- st.radio('Radio', [1,2,3])
85
- st.selectbox('Select', [1,2,3])
86
- st.multiselect('Multiselect', [1,2,3])
87
- st.slider('Slide me', min_value=0, max_value=10)
88
- st.select_slider('Slide to select', options=[1,'2'])
89
- st.text_input('Enter some text')
90
- st.number_input('Enter a number')
91
- st.text_area('Area for textual entry')
92
- st.date_input('Date input')
93
- st.time_input('Time entry')
94
- st.file_uploader('File uploader')
95
- st.color_picker('Pick a color')
96
- ''')
97
- col2.write('Use widgets\' returned values in variables:')
98
- col2.code('''
99
- for i in range(int(st.number_input('Num:'))):
100
- foo()
 
 
 
 
1
  import streamlit as st
2
  import pandas as pd
3
+ import random
4
 
5
  # Magic commands
6
+ st.set_page_config(page_title='Streamlit Super Power Cheat Sheet - Gamified')
 
7
  st.set_option('deprecation.showfileUploaderEncoding', False)
8
 
9
+ # Define player cards
10
+ player1 = [{'Word': 'Strategy', 'Definition': 'A plan of action designed to achieve a long-term or overall aim.'},
11
+ {'Word': 'Economics', 'Definition': 'The branch of knowledge concerned with the production, consumption, and transfer of wealth.'},
12
+ {'Word': 'Industry', 'Definition': 'Economic activity concerned with the processing of raw materials and manufacture of goods in factories.'}]
13
+
14
+ player2 = [{'Word': 'Manufacturing', 'Definition': 'The making of articles on a large scale using machinery.'},
15
+ {'Word': 'Transportation', 'Definition': 'The action of transporting someone or something or the process of being transported.'},
16
+ {'Word': 'Community', 'Definition': 'A group of people living in the same place or having a particular characteristic in common.'}]
17
+
18
+ # Create dataframes for each player card
19
+ df_player1 = pd.DataFrame(player1)
20
+ df_player2 = pd.DataFrame(player2)
21
+
22
+ # Merge the dataframes on word matches
23
+ df_matches = pd.merge(df_player1, df_player2, on='Word')
24
+
25
+ # Display the merged dataframe
26
+ st.dataframe(df_matches)
27
+
28
+ # Display the word match count
29
+ match_count = df_matches.shape[0]
30
+ st.write(f'Number of word matches: {match_count}')
31
+
32
+ # Display a random word match
33
+ if match_count > 0:
34
+ random_match = df_matches.iloc[random.randint(0, match_count-1)]
35
+ st.write(f'Random match: {random_match["Word"]}')
36
+ st.write(f'{random_match["Definition_x"]}')
37
+ st.write(f'{random_match["Definition_y"]}')
38
+ else:
39
+ st.write('No word matches')
40
+
41
+ # Emoji graphics
42
+ AI = 'πŸ€–'
43
+ DATA = 'πŸ“Š'
44
+ EMOJIS = ['🀣', 'πŸ˜‚', '😜', 'πŸ€ͺ', '😎', 'πŸ€”']
45
+
46
+ # strategy data
47
+ import pandas as pd
48
+
49
+ # Define the strategy classifications and their definitions
50
+ strategy_data = [
51
+ {'Classification': 'Economic', 'Definition': 'πŸ’° The branch of knowledge concerned with the production, consumption, and transfer of wealth.'},
52
+ {'Classification': 'Industry', 'Definition': '🏭 Economic activity concerned with the processing of raw materials and manufacture of goods in factories.'},
53
+ {'Classification': 'Manufacturing', 'Definition': '🏭 The making of articles on a large scale using machinery.'},
54
+ {'Classification': 'Development', 'Definition': 'πŸ—οΈ The process of growth, progress, or realization of goals.'},
55
+ {'Classification': 'Transport', 'Definition': 'πŸš— The movement of people, goods, or materials from one place to another.'},
56
+ {'Classification': 'Income', 'Definition': 'πŸ’Έ The money received by a person, company, or country for work, services, or investment.'},
57
+ {'Classification': 'Market', 'Definition': 'πŸ“ˆ A regular gathering of people for the purchase and sale of goods.'},
58
+ {'Classification': 'Network', 'Definition': '🌐 A group of interconnected people, companies, or devices that share information or resources.'},
59
+ ]
60
+
61
+ st.markdown("""
62
+ Classification Definition
63
+ 0 Economic πŸ’° The branch of knowledge concerned with the p...
64
+ 1 Industry 🏭 Economic activity concerned with the process...
65
+ 2 Manufacturing 🏭 The making of articles on a large scale usin...
66
+ 3 Development πŸ—οΈ The process of growth, progress, or realiz...
67
+ 4 Transport πŸš— The movement of people, goods, or materials ...
68
+ 5 Income πŸ’Έ The money received by a person, company, or ...
69
+ 6 Market πŸ“ˆ A regular gathering of people for the purcha...
70
+ 7 Network 🌐 A group of interconnected people, companies,...
71
+ """)
72
+
73
+ # Create a dataframe from the strategy data
74
+ df_strategy = pd.DataFrame(strategy_data)
75
+
76
+ # Display the dataframe
77
+ print(df_strategy)
78
+
79
+
80
+ # Example AI data
81
+ ai_data = {'accuracy': 0.89, 'precision': 0.72, 'recall': 0.64, 'f1': 0.68}
82
+
83
+ # One-liner functions
84
+ st.write(f"{AI} I'm sorry Dave, I'm afraid I can't do that.")
85
+ st.dataframe(pd.DataFrame(ai_data, index=['Model']))
86
+ st.table(pd.DataFrame(ai_data, index=['Model']))
87
+ st.json({'foo':'bar', 'fu':'ba', 'ai_data': ai_data})
88
+ st.metric(label="Model Accuracy", value=ai_data['accuracy'], delta=0.02)
89
+ st.button('Hit me ' + random.choice(EMOJIS))
90
+ st.download_button('On the dl', pd.DataFrame({'foo': [1,2,3], 'bar': [4,5,6]}))
91
+ st.checkbox('Tickle me ' + random.choice(EMOJIS))
92
+ st.radio('Choose your favorite ' + DATA, ['Bar chart', 'Pie chart', 'Line chart'])
93
+ st.selectbox('Select your ' + DATA, ['Sales', 'Expenses', 'Profits'])
94
+ st.multiselect('Pick your favorite ' + DATA + 's', ['Revenue', 'Profit', 'Loss'])
95
+ st.slider('Slide to ' + DATA, min_value=0, max_value=10)
96
+ st.select_slider('Slide to select your favorite ' + DATA, options=[1,2,3,4])
97
+ st.text_input('Enter some ' + DATA)
98
+ st.number_input('Enter a random ' + DATA + ' value')
99
+ st.text_area('Type something ' + random.choice(EMOJIS) + ' here')
100
+ st.date_input('Choose a ' + random.choice(['start', 'end']) + ' ' + DATA + ' date')
101
+ st.time_input('What time is it? ' + random.choice(EMOJIS))
102
+ st.file_uploader('Upload your favorite ' + DATA + ' ' + random.choice(EMOJIS))
103
+ st.color_picker('Pick a ' + DATA + ' ' + random.choice(EMOJIS))