iqra785 commited on
Commit
b2fed43
·
verified ·
1 Parent(s): 1e62e94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +127 -28
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 for the app
9
  st.markdown("""
10
  <style>
11
  .main .block-container {
@@ -15,19 +15,56 @@ st.markdown("""
15
  text-align: center;
16
  margin-bottom: 1rem;
17
  }
 
 
 
 
18
  .text-area {
19
  margin-top: 1rem;
20
  margin-bottom: 1rem;
21
  }
22
- .question-list {
23
- margin-top: 1rem;
 
 
24
  }
25
- .question {
26
- padding: 1rem;
27
- border: 1px solid #ddd;
 
28
  border-radius: 5px;
 
 
29
  background-color: #f9f9f9;
30
- margin-bottom: 0.5rem;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
32
  </style>
33
  """, unsafe_allow_html=True)
@@ -35,14 +72,18 @@ st.markdown("""
35
  # Initialize session state variables if not already set
36
  if 'input_text' not in st.session_state:
37
  st.session_state.input_text = ""
38
- if 'questions' not in st.session_state:
39
- st.session_state.questions = ""
 
 
 
 
40
 
41
  # Display the title and introduction
42
  st.title("InsightStarfleet")
43
  st.write("""
44
- Welcome to the InsightStarfleet! This application helps you summarize, and generate main points and flash cards based on the input text.
45
- Enter your text below, and click the button to generate questions.
46
  """)
47
 
48
  # Input area for text
@@ -52,7 +93,7 @@ input_text = st.text_area(
52
  value=st.session_state.input_text,
53
  height=200,
54
  key="input_text",
55
- help="Paste or type your text here to generate questions."
56
  )
57
 
58
  # Update session state if input text changes
@@ -63,30 +104,88 @@ if input_text != st.session_state.input_text:
63
  if st.session_state.input_text:
64
  AI71_API_KEY = get_ai71_api_key()
65
 
66
- st.subheader("Generate Questions")
67
 
68
  # Caching API call function
69
  @st.cache_data
70
  def generate_response(system_message, user_message):
71
  return _generate_response(system_message, user_message)
72
 
73
- # Button for generating questions
74
- if st.button("Generate Questions"):
75
- questions_prompt = "Generate questions based on the following text:"
76
- st.session_state.questions = generate_response(questions_prompt, st.session_state.input_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
- # Display generated questions
79
- if st.session_state.questions:
80
- st.subheader("Generated Questions")
81
- question_list = st.session_state.questions.split('\n') # Assuming questions are separated by newlines
82
- st.markdown('<div class="question-list">', unsafe_allow_html=True)
83
- for question in question_list:
84
- if question.strip():
85
- st.markdown(f"<div class='question'>{question.strip()}</div>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  st.markdown('</div>', unsafe_allow_html=True)
87
  st.download_button(
88
- label="Download Questions",
89
- data=st.session_state.questions,
90
- file_name="questions.txt",
91
  mime="text/plain"
92
  )
 
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 {
 
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-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: black;
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)
 
72
  # Initialize session state variables if not already set
73
  if 'input_text' not in st.session_state:
74
  st.session_state.input_text = ""
75
+ if 'summary' not in st.session_state:
76
+ st.session_state.summary = ""
77
+ if 'main_points' not in st.session_state:
78
+ st.session_state.main_points = ""
79
+ if 'flashcards' not in st.session_state:
80
+ st.session_state.flashcards = ""
81
 
82
  # Display the title and introduction
83
  st.title("InsightStarfleet")
84
  st.write("""
85
+ Welcome to the InsightStarfleet! This application helps you process text by summarizing content,
86
+ extracting main points, and creating flashcards. Follow the instructions to enter your text and generate content.
87
  """)
88
 
89
  # Input area for text
 
93
  value=st.session_state.input_text,
94
  height=200,
95
  key="input_text",
96
+ help="Paste or type your text here for processing."
97
  )
98
 
99
  # Update session state if input text changes
 
104
  if st.session_state.input_text:
105
  AI71_API_KEY = get_ai71_api_key()
106
 
107
+ st.subheader("Text Processing")
108
 
109
  # Caching API call function
110
  @st.cache_data
111
  def generate_response(system_message, user_message):
112
  return _generate_response(system_message, user_message)
113
 
114
+ # Buttons for processing
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. Ensure each flashcard includes a question and its corresponding answer, formatted as 'Question: [question]\\nAnswer: [answer]':"
125
+ st.session_state.flashcards = generate_response(flashcards_prompt, st.session_state.input_text)
126
+
127
+ # Combined Results
128
+ st.subheader("Results")
129
+
130
+ # Summary
131
+ if st.session_state.summary:
132
+ st.markdown("### Summary")
133
+ st.text_area(
134
+ "Summary",
135
+ value=st.session_state.summary,
136
+ height=200,
137
+ key="summary_results",
138
+ help="Generated summary."
139
+ )
140
+ st.download_button(
141
+ label="Download Summary",
142
+ data=st.session_state.summary,
143
+ file_name="summary.txt",
144
+ mime="text/plain"
145
+ )
146
+
147
+ # Main Points
148
+ if st.session_state.main_points:
149
+ st.markdown("### Main Points")
150
+ bullet_points = "\n".join([f"- {point.strip()}" for point in st.session_state.main_points.split("\n")])
151
+ st.markdown(f"### Main Points\n{bullet_points}", unsafe_allow_html=True)
152
+ st.download_button(
153
+ label="Download Main Points",
154
+ data=bullet_points,
155
+ file_name="main_points.txt",
156
+ mime="text/plain"
157
+ )
158
 
159
+ # Flashcards
160
+ if st.session_state.flashcards:
161
+ st.markdown("### Flashcards")
162
+ flashcards = st.session_state.flashcards.split("\n\n") # Assuming flashcards are separated by double newlines
163
+ st.markdown('<div class="flashcard-container">', unsafe_allow_html=True)
164
+ for card in flashcards:
165
+ try:
166
+ # Check if card contains both question and answer
167
+ if '\n' in card:
168
+ question, answer = card.split('\n', 1)
169
+ st.markdown(f"""
170
+ <div class="flashcard">
171
+ <div class="flashcard-inner">
172
+ <div class="flashcard-front">
173
+ <p>{question.strip()}</p>
174
+ </div>
175
+ <div class="flashcard-back">
176
+ <p>{answer.strip()}</p>
177
+ </div>
178
+ </div>
179
+ </div>
180
+ """, unsafe_allow_html=True)
181
+ else:
182
+ st.error("Invalid flashcard format. Each flashcard should be in 'question\\nanswer' format.")
183
+ except Exception as e:
184
+ st.error(f"Error processing flashcard: {e}")
185
  st.markdown('</div>', unsafe_allow_html=True)
186
  st.download_button(
187
+ label="Download Flashcards",
188
+ data=st.session_state.flashcards,
189
+ file_name="flashcards.txt",
190
  mime="text/plain"
191
  )