Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
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 |
-
.
|
23 |
-
|
|
|
|
|
24 |
}
|
25 |
-
.
|
26 |
-
|
27 |
-
|
|
|
28 |
border-radius: 5px;
|
|
|
|
|
29 |
background-color: #f9f9f9;
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 '
|
39 |
-
st.session_state.
|
|
|
|
|
|
|
|
|
40 |
|
41 |
# Display the title and introduction
|
42 |
st.title("InsightStarfleet")
|
43 |
st.write("""
|
44 |
-
Welcome to the InsightStarfleet! This application helps you
|
45 |
-
|
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
|
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("
|
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 |
-
#
|
74 |
-
if st.button("Generate
|
75 |
-
|
76 |
-
st.session_state.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
|
78 |
-
#
|
79 |
-
if st.session_state.
|
80 |
-
st.
|
81 |
-
|
82 |
-
st.markdown('<div class="
|
83 |
-
for
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
st.markdown('</div>', unsafe_allow_html=True)
|
87 |
st.download_button(
|
88 |
-
label="Download
|
89 |
-
data=st.session_state.
|
90 |
-
file_name="
|
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 |
)
|