iqra785 commited on
Commit
9391528
·
verified ·
1 Parent(s): 9ac70f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -14
app.py CHANGED
@@ -5,13 +5,75 @@ from ai_utils import generate_response as _generate_response
5
  # Set the page configuration to wide layout
6
  st.set_page_config(layout="wide")
7
 
8
- # Load external CSS
9
- with open("styles.css") as f:
10
- st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
11
-
12
- # Load HTML structure
13
- with open("index.html") as f:
14
- html_template = f.read()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  # Initialize session state variables if not already set
17
  if 'input_text' not in st.session_state:
@@ -108,13 +170,13 @@ if st.session_state.main_points:
108
  if st.session_state.flashcards:
109
  st.markdown("### Flashcards")
110
  flashcards = st.session_state.flashcards.split("\n\n") # Assuming flashcards are separated by double newlines
111
- flashcards_html = ""
112
  for card in flashcards:
113
  try:
114
  # Check if card contains both question and answer
115
  if '\n' in card:
116
  question, answer = card.split('\n', 1)
117
- flashcards_html += f"""
118
  <div class="flashcard">
119
  <div class="flashcard-inner">
120
  <div class="flashcard-front">
@@ -125,15 +187,12 @@ if st.session_state.flashcards:
125
  </div>
126
  </div>
127
  </div>
128
- """
129
  else:
130
  st.error("Invalid flashcard format. Each flashcard should be in 'question\\nanswer' format.")
131
  except Exception as e:
132
  st.error(f"Error processing flashcard: {e}")
133
-
134
- # Inject the flashcards into the HTML template
135
- st.markdown(html_template.replace("<!-- Flashcards will be injected here by Streamlit -->", flashcards_html), unsafe_allow_html=True)
136
-
137
  st.download_button(
138
  label="Download Flashcards",
139
  data=st.session_state.flashcards,
 
5
  # Set the page configuration to wide layout
6
  st.set_page_config(layout="wide")
7
 
8
+ # Custom CSS to style the page, text area, and flashcards
9
+ st.markdown("""
10
+ <style>
11
+ .main .block-container {
12
+ padding: 2rem;
13
+ }
14
+ .title {
15
+ text-align: center;
16
+ margin-bottom: 1rem;
17
+ }
18
+ .section-title {
19
+ margin-top: 2rem;
20
+ font-size: 1.5rem;
21
+ }
22
+ .text-area {
23
+ margin-top: 1rem;
24
+ margin-bottom: 1rem;
25
+ }
26
+ .flashcard-container {
27
+ display: flex;
28
+ flex-direction: row; /* Aligns flashcards horizontally */
29
+ overflow-x: auto; /* Allows horizontal scrolling if necessary */
30
+ gap: 20px; /* Adds space between flashcards */
31
+ padding: 1rem;
32
+ }
33
+ .flashcard {
34
+ width: 250px;
35
+ height: 200px;
36
+ border: 2px solid #4682b4; /* Steel Blue border */
37
+ border-radius: 5px;
38
+ font-size: 16px;
39
+ color: black;
40
+ background-color: #f0f8ff; /* Alice Blue background */
41
+ perspective: 1000px;
42
+ cursor: pointer;
43
+ display: flex;
44
+ align-items: center;
45
+ justify-content: center;
46
+ flex-shrink: 0; /* Prevent shrinking */
47
+ }
48
+ .flashcard-inner {
49
+ position: relative;
50
+ width: 100%;
51
+ height: 100%;
52
+ transition: transform 0.6s;
53
+ transform-style: preserve-3d;
54
+ }
55
+ .flashcard:hover .flashcard-inner {
56
+ transform: rotateY(180deg);
57
+ }
58
+ .flashcard-front, .flashcard-back {
59
+ position: absolute;
60
+ width: 100%;
61
+ height: 100%;
62
+ backface-visibility: hidden;
63
+ display: flex;
64
+ align-items: center;
65
+ justify-content: center;
66
+ padding: 1rem;
67
+ }
68
+ .flashcard-front {
69
+ background-color: #f0f8ff; /* Alice Blue background */
70
+ }
71
+ .flashcard-back {
72
+ background-color: #ffffff; /* White background for the back */
73
+ transform: rotateY(180deg);
74
+ }
75
+ </style>
76
+ """, unsafe_allow_html=True)
77
 
78
  # Initialize session state variables if not already set
79
  if 'input_text' not in st.session_state:
 
170
  if st.session_state.flashcards:
171
  st.markdown("### Flashcards")
172
  flashcards = st.session_state.flashcards.split("\n\n") # Assuming flashcards are separated by double newlines
173
+ st.markdown('<div class="flashcard-container">', unsafe_allow_html=True)
174
  for card in flashcards:
175
  try:
176
  # Check if card contains both question and answer
177
  if '\n' in card:
178
  question, answer = card.split('\n', 1)
179
+ st.markdown(f"""
180
  <div class="flashcard">
181
  <div class="flashcard-inner">
182
  <div class="flashcard-front">
 
187
  </div>
188
  </div>
189
  </div>
190
+ """, unsafe_allow_html=True)
191
  else:
192
  st.error("Invalid flashcard format. Each flashcard should be in 'question\\nanswer' format.")
193
  except Exception as e:
194
  st.error(f"Error processing flashcard: {e}")
195
+ st.markdown('</div>', unsafe_allow_html=True)
 
 
 
196
  st.download_button(
197
  label="Download Flashcards",
198
  data=st.session_state.flashcards,