awacke1 commited on
Commit
066701f
·
verified ·
1 Parent(s): 3cfbbfb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +319 -29
app.py CHANGED
@@ -1,41 +1,331 @@
 
1
  import streamlit as st
2
  import pandas as pd
3
  import numpy as np
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- st.set_page_config(layout="wide")
 
 
 
6
 
7
- # Custom CSS for larger font
8
- st.markdown("""
9
- <style>
10
- .stDataFrame {
11
- font-size: 20px;
12
- }
13
- .stMarkdown {
14
- font-size: 24px;
15
- }
16
- </style>
17
- """, unsafe_allow_html=True)
18
 
19
- # Load dataset
20
- def load_data():
21
- return pd.read_csv('https://raw.githubusercontent.com/manann/quotes-500k/main/quotes.csv', index_col=0)
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- quotes_data = load_data()
 
 
 
 
24
 
25
- # Sidebar
26
- st.sidebar.title("🔄 Refresh")
27
- if st.sidebar.button("🎲 New Quotes"):
28
- st.rerun()
29
 
30
- # Main content
31
- st.title("🌟 Famous Quotes Generator")
32
- st.write("📜 Here are 10 random famous quotes!")
 
33
 
34
- # Generate random list
35
- random_list = np.random.choice(quotes_data.index.values, 10, replace=False)
36
- random_quotes = quotes_data.loc[random_list]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
- # Display random list
39
- st.dataframe(random_quotes[['quote', 'author']], use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- st.markdown("📚 Source: [Kaggle - Quotes 500k](https://www.kaggle.com/datasets/manann/quotes-500k)")
 
 
1
+
2
  import streamlit as st
3
  import pandas as pd
4
  import numpy as np
5
+ import time
6
+ import random
7
+ import os
8
+ import hashlib
9
+ import json
10
+ from datetime import datetime
11
+
12
+ @st.cache_data
13
+ def load_famous_quotes():
14
+ famous_quotes = [
15
+ {"Number": 1, "Quote Topic": "Imagination", "Quote": "The true sign of intelligence is not knowledge but imagination. – Albert Einstein"},
16
+ {"Number": 2, "Quote Topic": "Perseverance", "Quote": "I have not failed. I've just found 10,000 ways that won't work. – Thomas Edison"},
17
+ {"Number": 3, "Quote Topic": "Innovation", "Quote": "Innovation distinguishes between a leader and a follower. – Steve Jobs"},
18
+ {"Number": 4, "Quote Topic": "Research", "Quote": "Research is what I'm doing when I don't know what I'm doing. – Wernher von Braun"},
19
+ {"Number": 5, "Quote Topic": "Possibility", "Quote": "The only way to discover the limits of the possible is to go beyond them into the impossible. – Arthur C. Clarke"},
20
+ {"Number": 6, "Quote Topic": "Success", "Quote": "Success is a science; if you have the conditions, you get the result. – Oscar Wilde"},
21
+ {"Number": 7, "Quote Topic": "Expertise", "Quote": "An expert is a person who has made all the mistakes that can be made in a very narrow field. – Niels Bohr"},
22
+ {"Number": 8, "Quote Topic": "Curiosity", "Quote": "The important thing is to not stop questioning. Curiosity has its own reason for existing. – Albert Einstein"},
23
+ {"Number": 9, "Quote Topic": "Future", "Quote": "The best way to predict the future is to invent it. – Alan Kay"},
24
+ {"Number": 10, "Quote Topic": "Progress", "Quote": "If I have seen further it is by standing on the shoulders of Giants. – Isaac Newton"},
25
+ {"Number": 11, "Quote Topic": "Logic and Imagination", "Quote": "Logic will get you from A to B. Imagination will take you everywhere. – Albert Einstein"},
26
+ {"Number": 12, "Quote Topic": "Imagination", "Quote": "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world. – Albert Einstein"},
27
+ {"Number": 13, "Quote Topic": "Science", "Quote": "Science is a way of thinking much more than it is a body of knowledge. – Carl Sagan"},
28
+ {"Number": 14, "Quote Topic": "Problem Solving", "Quote": "We cannot solve our problems with the same thinking we used when we created them. – Albert Einstein"},
29
+ {"Number": 15, "Quote Topic": "Experimentation", "Quote": "The true method of knowledge is experiment. – William Blake"},
30
+ {"Number": 16, "Quote Topic": "Questions", "Quote": "The scientist is not a person who gives the right answers, he's one who asks the right questions. – Claude Levi-Strauss"},
31
+ {"Number": 17, "Quote Topic": "Possibility", "Quote": "It's kind of fun to do the impossible. – Walt Disney"},
32
+ {"Number": 18, "Quote Topic": "Technology", "Quote": "Any sufficiently advanced technology is indistinguishable from magic. – Arthur C. Clarke"},
33
+ {"Number": 19, "Quote Topic": "Creativity", "Quote": "Creativity is intelligence having fun. – Albert Einstein"},
34
+ {"Number": 20, "Quote Topic": "Invention", "Quote": "To invent, you need a good imagination and a pile of junk. – Thomas Edison"}
35
+ ]
36
+ return pd.DataFrame(famous_quotes)
37
+
38
+ # Predefined custom quotes
39
+ custom_quotes = [
40
+ {"Number": 1, "Quote Topic": "Stages of Life 🌱", "Quote": "Every age unfolds a new lesson. Life's chapters evolve, each teaching us anew."},
41
+ {"Number": 2, "Quote Topic": "Stages of Life 🌱", "Quote": "From infancy to twilight, our journey is painted in growth. Every stage shines with its own wisdom."},
42
+ {"Number": 3, "Quote Topic": "Identity 🎭", "Quote": "We piece together our identity with experiences. In the vast cosmos, our ever-changing signature is our identity."},
43
+ {"Number": 4, "Quote Topic": "Identity 🎭", "Quote": "We aren't born with a defined self. Our identity is an art, crafted through introspection and encounters."},
44
+ {"Number": 5, "Quote Topic": "Enlightenment 💡", "Quote": "Every step towards enlightenment is a dive within. It's an ongoing journey of self and universe."},
45
+ {"Number": 6, "Quote Topic": "Enlightenment 💡", "Quote": "True insight isn't just about knowledge. It's the harmony of mind, heart, and soul."},
46
+ {"Number": 7, "Quote Topic": "Adaptive Resonance Theory 🧠", "Quote": "Our cognition is like a river, ever-flowing and adapting. Every experience shapes its course, forming new resonances."},
47
+ {"Number": 8, "Quote Topic": "Adaptive Resonance Theory 🧠", "Quote": "The brain's capacity to learn is profound. It finds its rhythm in adaptive resonances."},
48
+ {"Number": 9, "Quote Topic": "Panpsychism 🌌", "Quote": "The universe might hum with consciousness in every atom. Every speck could be part of this grand song."},
49
+ {"Number": 10, "Quote Topic": "Panpsychism 🌌", "Quote": "What if consciousness isn't exclusive to us? The universe's shared melody might be sung by all."},
50
+ {"Number": 11, "Quote Topic": "How to Think 🤔", "Quote": "Thinking isn't about arriving, it's about exploring. Dive deep, question, and embrace the universe within."},
51
+ {"Number": 12, "Quote Topic": "How to Think 🤔", "Quote": "To think profoundly is to touch the cosmos. It's about connecting with the vastness and intricacies it holds."},
52
+ {"Number": 13, "Quote Topic": "Plants Communication 🌿", "Quote": "In every leaf and root, plants tell tales of life. Their silent growth is a language we're just beginning to decipher."},
53
+ {"Number": 14, "Quote Topic": "Plants Communication 🌿", "Quote": "Nature's every rustle is a whispered secret. It's a testament to the intricate web of communication."},
54
+ {"Number": 15, "Quote Topic": "Fame 🌟", "Quote": "True impact outlives fleeting fame. What endures is the legacy we craft, not the applause we receive."},
55
+ {"Number": 16, "Quote Topic": "Fame 🌟", "Quote": "Fame might shine bright, but it's transient. Genuine influence is the silent footprint we leave in time."},
56
+ {"Number": 17, "Quote Topic": "Happiness 😊", "Quote": "True happiness is an inner light that shines brightest in shared moments."},
57
+ {"Number": 18, "Quote Topic": "Happiness 😊", "Quote": "Life's riches aren't material but the joyous moments and heartfelt memories we gather."},
58
+ {"Number": 19, "Quote Topic": "Exercise 🏃", "Quote": "Exercise is the symphony of the body, resonating with health and vitality."},
59
+ {"Number": 20, "Quote Topic": "Exercise 🏃", "Quote": "In movement, we find balance, strength, and a celebration of life's potential."},
60
+ {"Number": 21, "Quote Topic": "Good Habits 🔄", "Quote": "Good habits are the bricks that build the mansion of success."},
61
+ {"Number": 22, "Quote Topic": "Good Habits 🔄", "Quote": "Consistency in habits crafts our destiny, one action at a time."},
62
+ {"Number": 23, "Quote Topic": "Discipline 🕰️", "Quote": "Discipline is the bridge between dreams and their realization."},
63
+ {"Number": 24, "Quote Topic": "Discipline 🕰️", "Quote": "Through discipline, chaos transforms into order, and aspirations into achievements."},
64
+ {"Number": 25, "Quote Topic": "Stamina 🚀", "Quote": "Stamina isn't just enduring but thriving amidst challenges."},
65
+ {"Number": 26, "Quote Topic": "Stamina 🚀", "Quote": "It's stamina that turns obstacles into stepping stones, fueling our journey forward."},
66
+ {"Number": 27, "Quote Topic": "Artificial General Intelligence 🤯", "Quote": "AGI is not just about mimicking humans but understanding the core of intelligence itself."},
67
+ {"Number": 28, "Quote Topic": "Artificial General Intelligence 🤯", "Quote": "The pursuit of AGI is a testament to humanity's quest to transcend its own boundaries."},
68
+ {"Number": 29, "Quote Topic": "AI Pipelines 🛠️", "Quote": "AI pipelines are the arteries of intelligent systems, directing the flow of knowledge."},
69
+ {"Number": 30, "Quote Topic": "AI Pipelines 🛠️", "Quote": "In well-crafted pipelines, AI finds its rhythm, efficiency, and transformative power."},
70
+ {"Number": 31, "Quote Topic": "Genius 🌟", "Quote": "Genius isn't just raw talent; it's the alchemy of persistence, passion, and perspective."},
71
+ {"Number": 32, "Quote Topic": "Genius 🌟", "Quote": "Every spark of genius has been nurtured by curiosity and an insatiable thirst for knowledge."},
72
+ {"Number": 33, "Quote Topic": "Our Brains 🧠", "Quote": "Our brain is the universe's masterpiece, a nexus of thoughts, dreams, and memories."},
73
+ {"Number": 34, "Quote Topic": "Our Brains 🧠", "Quote": "In every neuron, our brain holds the potential of countless possibilities and imaginations."},
74
+ {"Number": 35, "Quote Topic": "Our Brains 🧠", "Quote": "The intricacies of our brain reflect the cosmos: vast, complex, and beautifully mysterious."},
75
+ {"Number": 36, "Quote Topic": "Our Brains 🧠", "Quote": "Understanding our brain is the key to unlocking the enigmas of consciousness, behavior, and potential."},
76
+ {"Number": 37, "Quote Topic": "Mindfulness 🌼", "Quote": "Mindfulness is the anchor that grounds us in the present, amidst life's tumultuous seas."},
77
+ {"Number": 38, "Quote Topic": "Mindfulness 🌼", "Quote": "In the act of being mindful, we embrace life's symphony, note by note, moment by moment."},
78
+ {"Number": 39, "Quote Topic": "Resilience 💪", "Quote": "Resilience is the art of bouncing back, turning wounds into wisdom and setbacks into comebacks."},
79
+ {"Number": 40, "Quote Topic": "Resilience 💪", "Quote": "Life will test us, but with resilience, we rise, stronger and more enlightened."},
80
+ {"Number": 41, "Quote Topic": "Innovation 💡", "Quote": "Innovation is the heartbeat of progress, pushing boundaries and redefining possibilities."},
81
+ {"Number": 42, "Quote Topic": "Innovation 💡", "Quote": "Every breakthrough, every invention, is a testament to humanity's relentless spirit of innovation."},
82
+ {"Number": 43, "Quote Topic": "Empathy ❤️", "Quote": "Empathy is the bridge between souls, transcending words and touching hearts."},
83
+ {"Number": 44, "Quote Topic": "Empathy ❤️", "Quote": "Through empathy, we see the world through another's eyes, fostering understanding and unity."},
84
+ {"Number": 45, "Quote Topic": "Happiness 😊", "Quote": "True happiness is an inner light that shines brightest in shared moments."},
85
+ {"Number": 46, "Quote Topic": "Happiness 😊", "Quote": "Life's riches aren't material but the joyous moments and heartfelt memories we gather."},
86
+ {"Number": 47, "Quote Topic": "Exercise 🏃", "Quote": "Exercise is the symphony of the body, resonating with health and vitality."},
87
+ {"Number": 48, "Quote Topic": "Exercise 🏃", "Quote": "In movement, we find balance, strength, and a celebration of life's potential."},
88
+ {"Number": 49, "Quote Topic": "Good Habits 🔄", "Quote": "Good habits are the bricks that build the mansion of success."},
89
+ {"Number": 50, "Quote Topic": "Good Habits 🔄", "Quote": "Consistency in habits crafts our destiny, one action at a time."},
90
+ {"Number": 51, "Quote Topic": "Discipline 🕰️", "Quote": "Discipline is the bridge between dreams and their realization."},
91
+ {"Number": 52, "Quote Topic": "Discipline 🕰️", "Quote": "Through discipline, chaos transforms into order, and aspirations into achievements."},
92
+ {"Number": 53, "Quote Topic": "Stamina 🚀", "Quote": "Stamina isn't just enduring but thriving amidst challenges."},
93
+ {"Number": 54, "Quote Topic": "Stamina 🚀", "Quote": "It's stamina that turns obstacles into stepping stones, fueling our journey forward."},
94
+ {"Number": 55, "Quote Topic": "Artificial General Intelligence 🤯", "Quote": "AGI is not just about mimicking humans but understanding the core of intelligence itself."},
95
+ {"Number": 56, "Quote Topic": "Artificial General Intelligence 🤯", "Quote": "The pursuit of AGI is a testament to humanity's quest to transcend its own boundaries."},
96
+ {"Number": 57, "Quote Topic": "AI Pipelines 🛠️", "Quote": "AI pipelines are the arteries of intelligent systems, directing the flow of knowledge."},
97
+ {"Number": 58, "Quote Topic": "AI Pipelines 🛠️", "Quote": "In well-crafted pipelines, AI finds its rhythm, efficiency, and transformative power."},
98
+ {"Number": 59, "Quote Topic": "Genius 🌟", "Quote": "Genius isn't just raw talent; it's the alchemy of persistence, passion, and perspective."},
99
+ {"Number": 60, "Quote Topic": "Genius 🌟", "Quote": "Every spark of genius has been nurtured by curiosity and an insatiable thirst for knowledge."},
100
+ {"Number": 61, "Quote Topic": "Our Brains 🧠", "Quote": "Our brain is the universe's masterpiece, a nexus of thoughts, dreams, and memories."},
101
+ {"Number": 62, "Quote Topic": "Our Brains 🧠", "Quote": "In every neuron, our brain holds the potential of countless possibilities and imaginations."},
102
+ {"Number": 63, "Quote Topic": "Our Brains 🧠", "Quote": "The intricacies of our brain reflect the cosmos: vast, complex, and beautifully mysterious."},
103
+ {"Number": 64, "Quote Topic": "Our Brains 🧠", "Quote": "Understanding our brain is the key to unlocking the enigmas of consciousness, behavior, and potential."},
104
+ {"Number": 65, "Quote Topic": "Mindfulness 🌼", "Quote": "Mindfulness is the anchor that grounds us in the present, amidst life's tumultuous seas."},
105
+ {"Number": 66, "Quote Topic": "Mindfulness 🌼", "Quote": "In the act of being mindful, we embrace life's symphony, note by note, moment by moment."},
106
+ {"Number": 67, "Quote Topic": "Resilience 💪", "Quote": "Resilience is the art of bouncing back, turning wounds into wisdom and setbacks into comebacks."},
107
+ {"Number": 68, "Quote Topic": "Resilience 💪", "Quote": "Life will test us, but with resilience, we rise, stronger and more enlightened."},
108
+ {"Number": 69, "Quote Topic": "Innovation 💡", "Quote": "Innovation is the heartbeat of progress, pushing boundaries and redefining possibilities."},
109
+ {"Number": 70, "Quote Topic": "Innovation 💡", "Quote": "Every breakthrough, every invention, is a testament to humanity's relentless spirit of innovation."},
110
+ {"Number": 71, "Quote Topic": "Empathy ❤️", "Quote": "Empathy is the bridge between souls, transcending words and touching hearts."},
111
+ {"Number": 72, "Quote Topic": "Empathy ❤️", "Quote": "Through empathy, we see the world through another's eyes, fostering understanding and unity."},
112
+ {"Number": 73, "Quote Topic": "Inspiration 🌈", "Quote": "Inspiration is the spark that ignites the soul, propelling us to chase our dreams."},
113
+ {"Number": 74, "Quote Topic": "Inspiration 🌈", "Quote": "Every moment of inspiration is a call to action, pushing us beyond our boundaries."},
114
+ {"Number": 75, "Quote Topic": "Learning 📚", "Quote": "Learning is the gateway to growth, opening doors to endless possibilities."},
115
+ {"Number": 76, "Quote Topic": "Learning 📚", "Quote": "Every lesson learned is a step towards enlightenment, broadening our horizons."},
116
+ {"Number": 77, "Quote Topic": "Collaboration 🤝", "Quote": "In collaboration, we find strength. Together, we achieve more than we could alone."},
117
+ {"Number": 78, "Quote Topic": "Collaboration 🤝", "Quote": "Unity in purpose paves the way for monumental achievements, showcasing the power of collective effort."},
118
+ {"Number": 79, "Quote Topic": "Dreams 🌌", "Quote": "Dreams are the architects of our future. They sketch the blueprint of our aspirations."},
119
+ {"Number": 80, "Quote Topic": "Dreams 🌌", "Quote": "In dreams, we find hope, and with hope, we transform the fabric of reality."},
120
+ {"Number": 81, "Quote Topic": "Courage 🦁", "Quote": "Courage is the fire that lights our path, even in the face of overwhelming odds."},
121
+ {"Number": 82, "Quote Topic": "Courage 🦁", "Quote": "With courage in our hearts, we defy limitations and embrace the vastness of potential."},
122
+ {"Number": 83, "Quote Topic": "Change 🌀", "Quote": "Change is life's only constant. It shapes, molds, and propels us forward."},
123
+ {"Number": 84, "Quote Topic": "Change 🌀", "Quote": "Embracing change is embracing growth, an acknowledgment of life's ever-evolving nature."},
124
+ {"Number": 85, "Quote Topic": "Adventure 🌍", "Quote": "Life is an adventure, filled with twists, turns, and unexpected discoveries."},
125
+ {"Number": 86, "Quote Topic": "Adventure 🌍", "Quote": "Every adventure, big or small, adds a chapter to our story, enriching our experience."},
126
+ {"Number": 87, "Quote Topic": "Creativity 🎨", "Quote": "Creativity is the dance of the soul, expressing itself in countless forms."},
127
+ {"Number": 88, "Quote Topic": "Creativity 🎨", "Quote": "Through creativity, we paint the world in vibrant colors, showcasing our unique perspectives."},
128
+ {"Number": 89, "Quote Topic": "Passion ❤️", "Quote": "Passion is the fuel for our journey, driving us to chase after our dreams."},
129
+ {"Number": 90, "Quote Topic": "Passion ❤️", "Quote": "With passion, every task becomes a labor of love, and every challenge, a thrilling endeavor."},
130
+ {"Number": 91, "Quote Topic": "Hope 🌟", "Quote": "Hope is the beacon that guides us through stormy nights, reminding us of the dawn that awaits."},
131
+ {"Number": 92, "Quote Topic": "Hope 🌟", "Quote": "In hope, we find solace, and in its embrace, we find the strength to persevere."},
132
+ {"Number": 93, "Quote Topic": "Intuition 🧭", "Quote": "Intuition is the silent whisper of the soul, guiding us with its subtle wisdom."},
133
+ {"Number": 94, "Quote Topic": "Intuition 🧭", "Quote": "By tuning into our intuition, we align with our inner compass, navigating life with clarity."},
134
+ {"Number": 95, "Quote Topic": "Joy 😃", "Quote": "Joy is the melody of the heart, a song of gratitude and love."},
135
+ {"Number": 96, "Quote Topic": "Joy 😃", "Quote": "In moments of joy, we connect with the essence of life, celebrating its beauty."},
136
+ {"Number": 97, "Quote Topic": "Wisdom 🦉", "Quote": "Wisdom is the culmination of experience, a treasure trove of insights and reflections."},
137
+ {"Number": 98, "Quote Topic": "Wisdom 🦉", "Quote": "With wisdom, we navigate life's complexities, drawing from the lessons of the past."},
138
+ {"Number": 99, "Quote Topic": "Love ❤️", "Quote": "Love is the universal language, transcending boundaries and touching souls."},
139
+ {"Number": 100, "Quote Topic": "Love ❤️", "Quote": "Through love, we find connection, unity, and the essence of existence."}
140
+ ]
141
+
142
+ # Function to display a quote
143
+ def display_quote(quote):
144
+ st.markdown(f"### {quote['Number']}. {quote['Quote Topic']}")
145
+ st.markdown(quote['Quote'])
146
+
147
+ # Function to generate a short user hash
148
+ def generate_user_hash():
149
+ if 'user_hash' not in st.session_state:
150
+ session_id = str(random.getrandbits(128))
151
+ hash_object = hashlib.md5(session_id.encode())
152
+ st.session_state['user_hash'] = hash_object.hexdigest()[:8]
153
+ return st.session_state['user_hash']
154
+
155
+ # Function to load vote history from file
156
+ def load_vote_history():
157
+ try:
158
+ with open('vote_history.json', 'r') as f:
159
+ return json.load(f)
160
+ except FileNotFoundError:
161
+ return {'images': {}, 'users': {}}
162
+
163
+ # Function to save vote history to file
164
+ def save_vote_history(history):
165
+ with open('vote_history.json', 'w') as f:
166
+ json.dump(history, f)
167
+
168
+ # Function to update vote history in Markdown file
169
+ def update_history_md(image_name, user_hash):
170
+ with open('history.md', 'a') as f:
171
+ f.write(f"- {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - User {user_hash} voted for {image_name}\n")
172
+
173
+ # Function to display images
174
+ def display_images(image_dir):
175
+ col1, col2 = st.columns(2)
176
+ valid_extensions = ('.png', '.jpg', '.jpeg', '.gif', '.bmp', '.tiff', '.webp')
177
+ images = [f for f in os.listdir(image_dir) if f.lower().endswith(valid_extensions)]
178
+
179
+ if len(images) < 2:
180
+ st.error("Not enough images in the directory.")
181
+ return
182
+
183
+ image1, image2 = random.sample(images, 2)
184
+ with col1:
185
+ st.image(os.path.join(image_dir, image1))
186
+ if st.button(f"Upvote {image1}", key=f"upvote_{image1}"):
187
+ handle_vote(image1)
188
+
189
+ with col2:
190
+ st.image(os.path.join(image_dir, image2))
191
+ if st.button(f"Upvote {image2}", key=f"upvote_{image2}"):
192
+ handle_vote(image2)
193
+
194
+ # Function to handle voting
195
+ def handle_vote(image_name):
196
+ user_hash = generate_user_hash()
197
+ vote_history = load_vote_history()
198
+
199
+ if image_name not in vote_history['images']:
200
+ vote_history['images'][image_name] = {'votes': 0, 'users': {}}
201
+
202
+ if user_hash not in vote_history['users']:
203
+ vote_history['users'][user_hash] = 0
204
+
205
+ vote_history['images'][image_name]['votes'] += 1
206
+ if user_hash not in vote_history['images'][image_name]['users']:
207
+ vote_history['images'][image_name]['users'][user_hash] = 0
208
+ vote_history['images'][image_name]['users'][user_hash] += 1
209
+ vote_history['users'][user_hash] += 1
210
+
211
+ save_vote_history(vote_history)
212
+ update_history_md(image_name, user_hash)
213
+ st.success(f"Upvoted {image_name}! Total votes: {vote_history['images'][image_name]['votes']}")
214
+
215
+ # Reset the timer when a vote is cast
216
+ st.session_state.last_interaction = time.time()
217
+
218
+ # Function to show vote history and user stats in sidebar
219
+ def show_vote_history():
220
+ st.sidebar.title("Vote History")
221
+ vote_history = load_vote_history()
222
+
223
+ # Sort users by total votes
224
+ sorted_users = sorted(vote_history['users'].items(), key=lambda x: x[1], reverse=True)
225
+
226
+ st.sidebar.subheader("User Vote Totals")
227
+ for user_hash, votes in sorted_users:
228
+ st.sidebar.write(f"User {user_hash}: {votes} votes")
229
+
230
+ # Sort images by vote count
231
+ sorted_images = sorted(vote_history['images'].items(), key=lambda x: x[1]['votes'], reverse=True)
232
+
233
+ st.sidebar.subheader("Image Vote Totals")
234
+ for i, (image_name, data) in enumerate(sorted_images):
235
+ votes = data['votes']
236
+ st.sidebar.write(f"{image_name}: {votes} votes")
237
+
238
+ # Display top 3 images
239
+ if i < 3:
240
+ st.sidebar.image(os.path.join('.', image_name), caption=f"#{i+1}: {image_name}", width=150)
241
 
242
+ # Main function
243
+ def main():
244
+ st.title("📝 Super Quote Generator with Image Voting")
245
+ st.write("Welcome to the Super Quote Generator! Enjoy famous and custom quotes with advanced features.")
246
 
247
+ # Initialize session states
248
+ if 'auto_repeat' not in st.session_state:
249
+ st.session_state.auto_repeat = "On"
250
+ if 'current_index' not in st.session_state:
251
+ st.session_state.current_index = random.randint(0, 19)
252
+ if 'quotes_list' not in st.session_state:
253
+ st.session_state.quotes_list = 'Famous Quotes'
254
+ if 'quotes_data' not in st.session_state:
255
+ st.session_state.quotes_data = pd.DataFrame()
256
+ if 'last_interaction' not in st.session_state:
257
+ st.session_state.last_interaction = time.time()
258
 
259
+ # Sidebar configuration
260
+ with st.sidebar:
261
+ st.header("Settings")
262
+ # Data source selection
263
+ st.session_state.quotes_list = st.radio("Select Quote Source:", ['Famous Quotes', 'Custom Quotes'])
264
+ # AutoRepeat toggle
265
+ st.session_state.auto_repeat = st.radio("🔄 AutoRepeat", ["On", "Off"], horizontal=True)
266
+ st.markdown("---")
267
+ st.write("Famous quotes provided by the app.")
268
+ # Display user hash
269
+ st.subheader("Your User ID")
270
+ st.write(generate_user_hash())
271
+ # Show vote history
272
+ show_vote_history()
273
 
274
+ # Load quotes data
275
+ if st.session_state.quotes_list == 'Famous Quotes':
276
+ st.session_state.quotes_data = load_famous_quotes()
277
+ else:
278
+ st.session_state.quotes_data = pd.DataFrame(custom_quotes)
279
 
280
+ # Display images for voting
281
+ image_dir = '.' # Current directory where the app is running
282
+ display_images(image_dir)
 
283
 
284
+ # Display the current quote
285
+ st.subheader("Quote of the Moment")
286
+ current_quote = st.session_state.quotes_data.iloc[st.session_state.current_index]
287
+ display_quote(current_quote)
288
 
289
+ # Timer logic
290
+ if st.session_state.auto_repeat == "On":
291
+ timer_placeholder = st.empty()
292
+ time_left = 10 - (time.time() - st.session_state.last_interaction)
293
+ if time_left <= 0:
294
+ # Alternate between the two quotes lists
295
+ if st.session_state.quotes_list == 'Famous Quotes':
296
+ st.session_state.quotes_list = 'Custom Quotes'
297
+ else:
298
+ st.session_state.quotes_list = 'Famous Quotes'
299
+ # Load the new quotes data
300
+ if st.session_state.quotes_list == 'Famous Quotes':
301
+ st.session_state.quotes_data = load_famous_quotes()
302
+ else:
303
+ st.session_state.quotes_data = pd.DataFrame(custom_quotes)
304
+ # Select a new random quote
305
+ st.session_state.current_index = random.randint(0, len(st.session_state.quotes_data) - 1)
306
+ st.session_state.last_interaction = time.time()
307
+ st.rerun()
308
+ else:
309
+ timer_placeholder.text(f"Time left: {int(time_left)} seconds")
310
+ else:
311
+ st.session_state.last_interaction = time.time()
312
 
313
+ # Manual refresh button
314
+ if st.button("Refresh Now"):
315
+ # Alternate between the two quotes lists
316
+ if st.session_state.quotes_list == 'Famous Quotes':
317
+ st.session_state.quotes_list = 'Custom Quotes'
318
+ else:
319
+ st.session_state.quotes_list = 'Famous Quotes'
320
+ # Load the new quotes data
321
+ if st.session_state.quotes_list == 'Famous Quotes':
322
+ st.session_state.quotes_data = load_famous_quotes()
323
+ else:
324
+ st.session_state.quotes_data = pd.DataFrame(custom_quotes)
325
+ # Select a new random quote
326
+ st.session_state.current_index = random.randint(0, len(st.session_state.quotes_data) - 1)
327
+ st.session_state.last_interaction = time.time()
328
+ st.rerun()
329
 
330
+ if __name__ == "__main__":
331
+ main()