awacke1's picture
Update app.py
871e091 verified
import streamlit as st
import random
import time
import os
def flatten_similes_metaphors(books):
return [simile for similes in books.values() for simile in similes]
def display_random_similes_metaphors(similes_metaphors):
display_lines = [""] * 5
while True:
random_samples = random.sample(similes_metaphors, 5)
display_lines = [sample.split(". ", 1)[1] for sample in random_samples]
simile_display = "\n".join([
f"# {line}" if i == 0 else
f"## {line}" if i == 1 else
f"### {line}" if i == 2 else
f"#### {line}" if i == 3 else
f"##### {line}"
for i, line in enumerate(display_lines)
])
st.markdown(simile_display)
time.sleep(1)
def display_book_list(books):
for book, samples in books.items():
st.header(book)
if samples:
for i, sample in enumerate(samples):
if f"likes_{book}_{i}" not in st.session_state:
st.session_state[f"likes_{book}_{i}"] = 0
col1, col2 = st.columns([9, 1])
with col1:
st.write(f"- {sample}")
with col2:
if st.button("πŸ‘", key=f"like_{book}_{i}"):
st.session_state[f"likes_{book}_{i}"] += 1
st.write(st.session_state[f"likes_{book}_{i}"])
else:
st.write("No similes or metaphors available for this book.")
def handle_feedback(feedback):
if not os.path.exists("feedback"):
os.makedirs("feedback")
with open("feedback/feedback.md", "a") as f:
f.write(f"- {feedback}\n")
def main():
books = {
"A Dictionary of Similes by Frank J. Wilstach": [
"1. As strong as an ox.",
"2. As proud as a peacock.",
"3. As gentle as a lamb.",
"4. As wise as an owl.",
"5. As brave as a lion.",
"6. As cunning as a fox.",
"7. As quiet as a mouse.",
"8. As happy as a lark.",
"9. As swift as a deer.",
"10. As sly as a fox.",
"11. As firm as a rock.",
"12. As light as air.",
"13. As soft as silk.",
"14. As hard as nails.",
"15. As deep as the ocean.",
"16. As warm as toast.",
"17. As cold as ice.",
"18. As fresh as a daisy.",
"19. As dark as night.",
"20. As bright as the sun."
],
"The Penguin Dictionary of Similes by Michael Fergusson": [
"21. As brave as a lion.",
"22. As cool as a cucumber.",
"23. As fit as a fiddle.",
"24. As gentle as a lamb.",
"25. As happy as a clam.",
"26. As light as a feather.",
"27. As old as the hills.",
"28. As right as rain.",
"29. As sharp as a tack.",
"30. As sick as a dog.",
"31. As silent as the grave.",
"32. As smooth as silk.",
"33. As snug as a bug in a rug.",
"34. As soft as velvet.",
"35. As stubborn as a mule.",
"36. As sure as death and taxes.",
"37. As sweet as honey.",
"38. As tough as nails."
],
"The Oxford Dictionary of Allusions by Andrew Delahunty and Sheila Dignen": [
"39. As dead as a dodo.",
"40. As easy as pie.",
"41. As free as a bird.",
"42. As hungry as a wolf.",
"43. As large as life.",
"44. As mad as a hatter.",
"45. As nutty as a fruitcake.",
"46. As plain as the nose on your face.",
"47. As quick as a wink.",
"48. As safe as houses.",
"49. As sound as a bell.",
"50. As steady as a rock.",
"51. As thick as thieves.",
"52. As tight as a drum.",
"53. As tough as old boots.",
"54. As true as steel.",
"55. As weak as a kitten.",
"56. As wise as Solomon."
],
"The Bloomsbury Dictionary of Idioms by Gordon Jarvie": [
"57. As drunk as a lord.",
"58. As flat as a pancake.",
"59. As keen as mustard.",
"60. As neat as a pin.",
"61. As pleased as punch."
],
"The American Heritage Dictionary of Idioms by Christine Ammer": [
"62. As drunk as a skunk.",
"63. As plain as day."
],
"Webster's New World Dictionary of Similes by Gail Weiss": [
"64. As pale as a ghost.",
"65. As busy as a bee.",
"66. As bold as brass.",
"67. As clear as crystal.",
"68. As good as gold.",
"69. As hot as hell.",
"70. As mad as a hornet.",
"71. As snug as a bug.",
"72. As tall as a tree.",
"73. As tough as leather."
],
"The Hutchinson Dictionary of Difficult Words by Terry O'Brien": [
"74. As black as coal.",
"75. As blind as a bat.",
"76. As bright as a button.",
"77. As clean as a whistle.",
"78. As dry as a bone.",
"79. As dull as dishwater."
],
"The Wordsworth Dictionary of Phrase and Fable by Ebenezer Cobham Brewer": [],
"The Macmillan Dictionary of Quotations by John Daintith and Amanda Isaacs": [
"80. As cold as charity.",
"81. As common as muck.",
"82. As cute as a button.",
"83. As easy as falling off a log.",
"84. As fast as lightning.",
"85. As hungry as a bear.",
"86. As mad as a hornet."
],
"The Chambers Dictionary of Idioms by Elizabeth McLaren Kirkpatrick": [
"87. As brown as a berry.",
"88. As dead as a doornail."
],
"The Routledge Dictionary of Modern American Slang and Unconventional English by Tom Dalzell": [
"89. As happy as a clam at high tide."
],
"The Faber Dictionary of Euphemisms by R. W. Holder": [
"90. As thin as a rake.",
"91. As black as pitch."
],
"The BBI Combinatory Dictionary of English: A Guide to Word Combinations by Morton Benson, Evelyn Benson, and Robert Ilson": [
"92. As easy as ABC.",
"93. As dry as dust.",
"94. As fresh as paint.",
"95. As happy as a sandboy."
],
"The Chambers Thesaurus by Chambers Harrap Publishers Ltd.": [
"96. As sly as a fox.",
"97. As large as life."
],
"The McGraw-Hill Dictionary of American Idioms and Phrasal Verbs by Richard A. Spears": [
"98. As white as snow.",
"99. As plain as the nose on your face."
],
"The Wordsworth Thesaurus by Wordsworth Editions Ltd.": [],
"The Oxford Dictionary of Idioms by Judith Siefring": [],
"The Penguin Thesaurus by Rosalind Fergusson": [
"100. As plain as the nose on your face."
],
"The Longman Dictionary of Contemporary English by Pearson Longman": [
"101. As quick as a wink."
],
"The American Heritage Thesaurus by Editors of the American Heritage Dictionaries": []
}
similes_metaphors = flatten_similes_metaphors(books)
st.title("Similes and Metaphors Compendium")
st.sidebar.title("Controls")
if st.sidebar.button("Start Timer"):
st.session_state.start_time = time.time()
st.session_state.timer_active = True
else:
st.session_state.timer_active = False
if st.session_state.timer_active:
elapsed_time = int(time.time() - st.session_state.start_time)
st.sidebar.write(f"Timer: {elapsed_time} seconds")
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
user_input = st.text_input("Enter your message:")
if user_input:
st.session_state.chat_history.append(("user", user_input))
ai_response = "I appreciate your message!"
emojis = ["😊", "πŸ˜„", "πŸ˜‡", "πŸ™Œ", "πŸ‘", "🌟", "πŸš€", "🌈", "πŸŽ‰", "🌞"]
random_emoji = random.choice(emojis)
st.session_state.chat_history.append(("assistant", f"{ai_response} {random_emoji}"))
for i, (sender, message) in enumerate(st.session_state.chat_history):
if sender == "user":
st.chat_message(message, avatar_style="adventurer")
if st.button("πŸ‘Ž", key=f"dislike_{i}"):
feedback = st.text_input("Please provide your feedback:", key=f"feedback_{i}")
if feedback:
handle_feedback(feedback)
st.markdown("Thank you for your feedback!")
st.download_button(
"Download Feedback",
data=feedback,
file_name="feedback.md",
mime="text/markdown"
)
else:
st.chat_message(message, key=f"assistant_{i}", avatar_style="persona")
tab1, tab2 = st.tabs(["Random Similes and Metaphors", "Book List"])
with tab1:
st.write("Randomly selected similes and metaphors:")
display_random_similes_metaphors(similes_metaphors)
with tab2:
display_book_list(books)
if __name__ == "__main__":
main()