Skip to content

Commit

Permalink
Suffle prompts, download button.
Browse files Browse the repository at this point in the history
  • Loading branch information
BSalita committed Sep 10, 2023
1 parent 936abcd commit c63dc5a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
12 changes: 9 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,9 +1082,15 @@ def create_main_section():
pdf_assets.append(df)
# else:
# st.dataframe(df.T.style.format(precision=2, thousands=""))
pdf_base64_encoded = streamlitlib.create_pdf(pdf_assets)
download_pdf_html = f'<a href="data:application/octet-stream;base64,{pdf_base64_encoded.decode()}" download="{st.session_state.game_id}-{st.session_state.player_number}-morty.pdf">Download Personalized Report</a>'
st.session_state.pdf_link.markdown(download_pdf_html, unsafe_allow_html=True) # pdf_link is really a previously created st.sidebar.empty().

if st.session_state.pdf_link.download_button(label="Download Personalized Report",
data=streamlitlib.create_pdf(pdf_assets),
file_name = f"{st.session_state.game_id}-{st.session_state.player_number}-morty.pdf",
mime='application/octet-stream'):
st.warning('download triggered') # todo: this never works. why?
#pdf_base64_encoded = streamlitlib.create_pdf(pdf_assets)
#download_pdf_html = f'<a href="data:application/octet-stream;base64,{pdf_base64_encoded.decode()}" download="{st.session_state.game_id}-{st.session_state.player_number}-morty.pdf">Download Personalized Report</a>'
#st.session_state.pdf_link.markdown(download_pdf_html, unsafe_allow_html=True) # pdf_link is really a previously created st.sidebar.empty().

# wish this would scroll to top of page but doesn't work.
# js = '''
Expand Down
44 changes: 27 additions & 17 deletions default.favorites.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,50 @@
"@Boards_We_Played",
"@Our_Best_Boards",
"@Our_Worst_Boards",
"@Boards_We_Beat_ParScore",
"@Boards_We_Equaled_ParScore",
"@Boards_We_Underperformed_ParScore",
"@Boards_I_Declared",
"@Boards_Partner_Declared",
"@Actual_Score_Pcts",
"@Boards_I_Underperformed_DD",
"@Boards_Partner_Underperformed_DD",
"@Single_Dummy_Our_Boards",
"@Single_Dummy_All_Boards",
"@Frequency_of_Contracts",
"@Wrong_Side",
"@Gifts",
"@Mistakes",
"@We_Underbid",
"@Opponent_Underbid",
"@We_Fixed_Opponents",
"@We_Got_Fixed",
"@Actual_Score_Pcts",
"@DD_Score_Pcts",
"@Par_Score_Pcts",
"@SD_Score_Pcts",
"@SD_Optimal_Score_Pcts",
"@ParScore_Rankings",
"@Percentage_Per_Round",
"@Frequency_of_Contracts",
"@Unique_Bids_All_Boards",
"@Unique_Bids_We_Played"
"@Unique_Bids_We_Played",
"@Boards_I_Underperformed_DD",
"@Boards_Partner_Underperformed_DD",
"@Boards_We_Beat_ParScore",
"@Boards_We_Equaled_ParScore",
"@Boards_We_Underperformed_ParScore",
"@Single_Dummy_Our_Boards",
"@Single_Dummy_All_Boards"
]
},
"Summarize_Expert_Only": {
"title": "Summarize -- Experts Only",
"Summarize_Briefly": {
"title": "Summarize Briefly",
"help": "Summarize the game's results. Expert statistics only.",
"comment": "@ in prompt means prompt is a key into ['SelectBoxes']['Vetted_Prompts'] list.",
"prompts": [
"@About",
"@Boards_We_Played",
"@Our_Best_Boards",
"@Our_Worst_Boards",
"@Boards_I_Declared",
"@Boards_Partner_Declared",
"@Actual_Score_Pcts",
"@DD_Score_Pcts",
"@Par_Score_Pcts",
"@SD_Score_Pcts",
"@SD_Optimal_Score_Pcts",
"@ParScore_Rankings"
"@Frequency_of_Contracts",
"@Gifts",
"@Mistakes",
"@Percentage_Per_Round"
]
}
},
Expand Down
4 changes: 2 additions & 2 deletions streamlitlib/streamlitlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def ShowDataFrameTable(table_df,key=None,output_method='aggrid',color_column=Non
import markdown
from xml.sax.saxutils import unescape
from bs4 import BeautifulSoup
import base64
#import base64

class HorizontalLine(Flowable):
"""A custom flowable that draws a horizontal line."""
Expand Down Expand Up @@ -313,5 +313,5 @@ def create_pdf(pdf_assets, output_filename=None):

# Return the bytes
#return buffer.getvalue()
return base64.b64encode(buffer.getvalue()) # return buffer.getvalue() or base64.b64encode(buffer.getvalue())?
return buffer.getvalue() # works for st.download() otherwise use base64.b64encode(buffer.getvalue()) # return buffer.getvalue() or base64.b64encode(buffer.getvalue())?

0 comments on commit c63dc5a

Please sign in to comment.