jnaiman commited on
Commit
27fd108
·
1 Parent(s): 9052957
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +25 -45
  3. requirements.txt +1 -1
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Prep notebook -- My Streamlit App
3
  emoji: 🏢
4
  colorFrom: blue
5
  colorTo: gray
 
1
  ---
2
+ title: Prep notebook -- My Streamlit App (Day 1)
3
  emoji: 🏢
4
  colorFrom: blue
5
  colorTo: gray
app.py CHANGED
@@ -1,12 +1,4 @@
1
 
2
-
3
-
4
- # day 2/3 -- "grab bag" of other things
5
- # multi-page apps? ==> maybe day 2? ==> does this work with HF apps??
6
- # Week 12 -- https://docs.streamlit.io/develop/tutorials/databases <- touch on but say we'll be just doing csv files
7
- # Week 12 -- embedding streamlit spaces on other webpages? wait until Jekyll? https://huggingface.co/docs/hub/en/spaces-sdks-streamlit#embed-streamlit-spaces-on-other-webpages
8
-
9
-
10
  #######################################################
11
  # 1. Getting setup -- using our HF template
12
  #######################################################
@@ -109,7 +101,7 @@ st.pyplot(fig)
109
  st.write('''The requirements.txt file contains all the packages needed
110
  for our app to run. These include (for our application):''')
111
  st.code('''
112
- streamlit
113
  altair
114
  numpy
115
  pandas
@@ -119,6 +111,8 @@ matplotlib
119
  # NOTE: for any package you want to use in your app.py file, you must include it in
120
  # the requirements.txt file!
121
 
 
 
122
  ### 3.3 Push these changes to HF -- README.md ###
123
 
124
  # While we're doing this, let's also take a look at the README.md file!
@@ -403,44 +397,30 @@ if len(states_selected2) > 0: # here we set a default value for the slider, so n
403
  fig2.savefig(buf2, format="png")
404
  fig_col2.image(buf2, width = 400) # changed here to fit better
405
  else:
406
- fig2,ax2 = plt.subplots(figsize=(4,8)) # this changed
407
- extent2 = [bins.min(), bins.max(), 0, len(table.index)]
408
- ax2.imshow(table.values, cmap='hot', interpolation='nearest', extent=extent2)
409
- ax2.set_yticks(range(len(table.index)))
410
- ax2.set_yticklabels(table.index)
411
-
412
- buf2 = BytesIO()
413
- fig2.tight_layout()
414
- fig2.savefig(buf2, format="png")
415
- fig_col2.image(buf2, width = 500) # can mess around with width, figsize/etc
416
-
417
- # THEN: slider for range of student teacher ratios -- do the RANGE slider: https://docs.streamlit.io/develop/api-reference/widgets/st.slider
418
-
419
- # with st.expander('Favorite product by Gender within city'):
420
- # column1, column2 = st.columns([3,1])
421
-
422
- # # Allow the user to select a gender.
423
- # selected_gender = st.radio('What is your Gender:', df.gender.unique(), index = 0)
424
-
425
- # # Apply gender filter.
426
- # gender_product = df[df['gender'] == selected_gender]
427
-
428
- # # Allow the user to select a city.
429
- # select_city = column2.selectbox('Select City', df.sort_values('City').City.unique())
430
 
431
- # # Apply city filter
432
- # city_gender_product = gender_product[gender_product['City'] == select_city]
433
 
434
- # # Use the city_gender_product dataframe as it has filters for gender and city.
435
- # fig = px.histogram(city_gender_product.sort_values('product_line') ,x='product_line', y='gross_income', color = 'product_line',)
436
 
437
- # if selected_gender == 'Male':
438
- # st.write('What men buy most!')
439
- # else:
440
- # st.write('What female buy most!')
441
 
442
- # st.plotly_chart(fig, use_container_width=True)
 
 
 
 
 
 
 
 
443
 
444
- ################################################
445
- # 5. TODO Multi-page apps (?) this might be for next week/extra
446
- ################################################
 
 
1
 
 
 
 
 
 
 
 
 
2
  #######################################################
3
  # 1. Getting setup -- using our HF template
4
  #######################################################
 
101
  st.write('''The requirements.txt file contains all the packages needed
102
  for our app to run. These include (for our application):''')
103
  st.code('''
104
+ streamlit==1.39.0
105
  altair
106
  numpy
107
  pandas
 
111
  # NOTE: for any package you want to use in your app.py file, you must include it in
112
  # the requirements.txt file!
113
 
114
+ # Note #2: we specified a version of streamlit so we can use some specific widgets
115
+
116
  ### 3.3 Push these changes to HF -- README.md ###
117
 
118
  # While we're doing this, let's also take a look at the README.md file!
 
397
  fig2.savefig(buf2, format="png")
398
  fig_col2.image(buf2, width = 400) # changed here to fit better
399
  else:
400
+ min_range = student_teacher_ratio_range[0] # added
401
+ max_range = student_teacher_ratio_range[1] # added
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
 
403
+ df_subset2 = df[(df['Student_teacher_ratio'] >= min_range) & (df['Student_teacher_ratio']<=max_range)] # changed
 
404
 
405
+ # just 10 bins over the full range --> changed
406
+ bins2 = 10 #np.linspace(df['Student_teacher_ratio'].min(),df['Student_teacher_ratio'].max(), 10)
407
 
408
+ # make pivot table -- changed
409
+ table_sub2 = df_subset2.pivot_table(index='State',
410
+ columns=pd.cut(df_subset2['Student_teacher_ratio'], bins2),
411
+ aggfunc='size')
412
 
413
+ base_size = 4
414
+ fig2,ax2 = plt.subplots(figsize=(base_size,2*base_size)) # this changed too for different size
415
+ extent2 = [df_subset2['Student_teacher_ratio'].min(),
416
+ df_subset2['Student_teacher_ratio'].max(),
417
+ 0, len(table_sub2.index)]
418
+ ax2.imshow(table_sub2.values, cmap='hot', interpolation='nearest', extent=extent2)
419
+ ax2.set_yticks(range(len(table_sub2.index)))
420
+ ax2.set_yticklabels(table_sub2.index)
421
+ #ax2.set_xticklabels()
422
 
423
+ buf2 = BytesIO()
424
+ fig2.tight_layout()
425
+ fig2.savefig(buf2, format="png")
426
+ fig_col2.image(buf2, width = 400) # changed here to fit better
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- streamlit
2
  altair
3
  numpy
4
  pandas
 
1
+ streamlit==1.39.0
2
  altair
3
  numpy
4
  pandas