iqra785 commited on
Commit
905424e
·
verified ·
1 Parent(s): 7b22dde

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -46
app.py CHANGED
@@ -5,7 +5,7 @@ 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
- # Custom CSS to style the page and text area
9
  st.markdown("""
10
  <style>
11
  .main .block-container {
@@ -23,17 +23,48 @@ st.markdown("""
23
  margin-top: 1rem;
24
  margin-bottom: 1rem;
25
  }
 
 
 
 
 
26
  .flashcard {
27
- border: 1px solid #ddd;
 
 
28
  border-radius: 5px;
29
- padding: 1rem;
30
- margin: 0.5rem 0;
31
  background-color: #f9f9f9;
 
 
32
  }
33
- .stTextArea textarea {
34
- font-size: 16px;
35
- border-radius: 5px;
36
- border: 2px solid #ddd;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  }
38
  </style>
39
  """, unsafe_allow_html=True)
@@ -80,60 +111,37 @@ if st.session_state.input_text:
80
  def generate_response(system_message, user_message):
81
  return _generate_response(system_message, user_message)
82
 
83
- # Buttons for processing
84
  if st.button("Generate Summary"):
85
  summary_prompt = "Summarize the following text into a brief summary:"
86
  st.session_state.summary = generate_response(summary_prompt, st.session_state.input_text)
87
- st.text_area("Summary", value=st.session_state.summary, height=200, key="summary", help="Summary of the input text.")
88
 
89
  if st.button("Extract Main Points"):
90
  main_points_prompt = "Extract the main points from the following text and format them as a bulleted list:"
91
  st.session_state.main_points = generate_response(main_points_prompt, st.session_state.input_text)
92
- # Format main points as a bulleted list
93
- if st.session_state.main_points:
94
- bullet_points = "\n".join([f"- {point.strip()}" for point in st.session_state.main_points.split("\n")])
95
- st.markdown(f"### Main Points\n{bullet_points}", unsafe_allow_html=True)
96
 
97
  if st.button("Generate Flashcards"):
98
  flashcards_prompt = "Create flashcards with questions and answers based on the following text:"
99
  st.session_state.flashcards = generate_response(flashcards_prompt, st.session_state.input_text)
100
 
101
- # Display flashcards as actual cards
102
  flashcards = st.session_state.flashcards.split("\n\n") # Assuming flashcards are separated by double newlines
 
103
  for card in flashcards:
 
104
  st.markdown(f"""
105
  <div class="flashcard">
106
- {card}
 
 
 
 
 
 
 
107
  </div>
108
  """, unsafe_allow_html=True)
 
109
 
110
- # Results
111
- if st.session_state.summary or st.session_state.main_points or st.session_state.flashcards:
112
- st.subheader("Results")
113
-
114
- st.subheader("Summary")
115
- st.text_area("Summary", value=st.session_state.summary, height=200, key="summary_results", help="Generated summary.")
116
-
117
- st.subheader("Main Points")
118
- if st.session_state.main_points:
119
- bullet_points = "\n".join([f"- {point.strip()}" for point in st.session_state.main_points.split("\n")])
120
- st.markdown(f"### Main Points\n{bullet_points}", unsafe_allow_html=True) # Displaying the main points as a bulleted list
121
-
122
- st.subheader("Flashcards")
123
- if st.session_state.flashcards:
124
- flashcards = st.session_state.flashcards.split("\n\n") # Assuming flashcards are separated by double newlines
125
- for card in flashcards:
126
- st.markdown(f"""
127
- <div class="flashcard">
128
- {card}
129
- </div>
130
- """, unsafe_allow_html=True)
131
-
132
- st.subheader("Download Results")
133
- results = f"Summary:\n{st.session_state.summary}\n\nMain Points:\n{st.session_state.main_points}\n\nFlashcards:\n{st.session_state.flashcards}"
134
- st.download_button(
135
- label="Download Results",
136
- data=results,
137
- file_name="results.txt",
138
- mime="text/plain"
139
- )
 
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 {
 
23
  margin-top: 1rem;
24
  margin-bottom: 1rem;
25
  }
26
+ .flashcard-container {
27
+ display: flex;
28
+ flex-wrap: wrap;
29
+ gap: 1rem;
30
+ }
31
  .flashcard {
32
+ width: 250px;
33
+ height: 200px;
34
+ border: 1px solid blue;
35
  border-radius: 5px;
36
+ font-size: 16px;
37
+ color: blue;
38
  background-color: #f9f9f9;
39
+ perspective: 1000px;
40
+ cursor: pointer;
41
  }
42
+ .flashcard-inner {
43
+ position: relative;
44
+ width: 100%;
45
+ height: 100%;
46
+ transition: transform 0.6s;
47
+ transform-style: preserve-3d;
48
+ }
49
+ .flashcard:hover .flashcard-inner {
50
+ transform: rotateY(180deg);
51
+ }
52
+ .flashcard-front, .flashcard-back {
53
+ position: absolute;
54
+ width: 100%;
55
+ height: 100%;
56
+ backface-visibility: hidden;
57
+ display: flex;
58
+ align-items: center;
59
+ justify-content: center;
60
+ padding: 1rem;
61
+ }
62
+ .flashcard-front {
63
+ background-color: #fff;
64
+ }
65
+ .flashcard-back {
66
+ background-color: #f9f9f9;
67
+ transform: rotateY(180deg);
68
  }
69
  </style>
70
  """, unsafe_allow_html=True)
 
111
  def generate_response(system_message, user_message):
112
  return _generate_response(system_message, user_message)
113
 
114
+ # Process the input text and generate results
115
  if st.button("Generate Summary"):
116
  summary_prompt = "Summarize the following text into a brief summary:"
117
  st.session_state.summary = generate_response(summary_prompt, st.session_state.input_text)
 
118
 
119
  if st.button("Extract Main Points"):
120
  main_points_prompt = "Extract the main points from the following text and format them as a bulleted list:"
121
  st.session_state.main_points = generate_response(main_points_prompt, st.session_state.input_text)
 
 
 
 
122
 
123
  if st.button("Generate Flashcards"):
124
  flashcards_prompt = "Create flashcards with questions and answers based on the following text:"
125
  st.session_state.flashcards = generate_response(flashcards_prompt, st.session_state.input_text)
126
 
127
+ # Display flashcards as interactive cards
128
  flashcards = st.session_state.flashcards.split("\n\n") # Assuming flashcards are separated by double newlines
129
+ st.markdown('<div class="flashcard-container">', unsafe_allow_html=True)
130
  for card in flashcards:
131
+ question, answer = card.split('\n', 1) # Assuming each card is in "question\nanswer" format
132
  st.markdown(f"""
133
  <div class="flashcard">
134
+ <div class="flashcard-inner">
135
+ <div class="flashcard-front">
136
+ <p>{question.strip()}</p>
137
+ </div>
138
+ <div class="flashcard-back">
139
+ <p>{answer.strip()}</p>
140
+ </div>
141
+ </div>
142
  </div>
143
  """, unsafe_allow_html=True)
144
+ st.markdown('</div>', unsafe_allow_html=True)
145
 
146
+ # Prepare results for download
147
+ if st.session_state.summary or st.session_state.main_points or st.session_state.flashcards: