Spaces:
Sleeping
Sleeping
File size: 5,801 Bytes
c05310b 9f8a212 f1e900a 08a0246 f1e900a 9391528 a47e38a 9391528 13bb687 9391528 a733938 4c93b81 a733938 4c93b81 2fc01da a733938 4c93b81 a733938 4c93b81 a733938 7b22dde b2fed43 7b22dde a733938 ba11d51 4c93b81 b2fed43 4c93b81 b2fed43 4c93b81 496c793 4c93b81 b2fed43 4c93b81 b2fed43 4c93b81 b2fed43 4c93b81 496c793 4c93b81 383b850 fd4fccc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
import streamlit as st
from config import get_ai71_api_key
from ai_utils import generate_response as _generate_response
# Set the page configuration to wide layout
st.set_page_config(layout="wide")
# Custom CSS to style the page, text area, and flashcards
st.markdown("""
<style>
.main .block-container {
padding: 2rem;
}
.title {
text-align: center;
margin-bottom: 1rem;
}
.section-title {
margin-top: 2rem;
font-size: 1.5rem;
}
.text-area {
margin-top: 1rem;
margin-bottom: 1rem;
}
.flashcard-container {
display: flex;
flex-direction: row; /* Aligns flashcards horizontally */
overflow-x: auto; /* Allows horizontal scrolling if necessary */
gap: 20px; /* Adds space between flashcards */
padding: 1rem;
}
.flashcard {
width: 250px;
height: 200px;
border: 2px solid #4682b4; /* Steel Blue border */
border-radius: 5px;
font-size: 16px;
color: black;
background-color: #f0f8ff; /* Alice Blue background */
perspective: 1000px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0; /* Prevent shrinking */}
.flashcard-inner {
position: relative;
width: 100%;
height: 100%;
transition: transform 0.6s;
transform-style: preserve-3d;
}
.flashcard:hover .flashcard-inner {
transform: rotateY(180deg);
}
.flashcard-front, .flashcard-back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
display: flex;
align-items: center;
justify-content: center;
padding: 1rem;
}
.flashcard-front {
background-color: #f0f8ff; /* Alice Blue background */
}
.flashcard-back {
background-color: #ffffff; /* White background for the back */
transform: rotateY(180deg);
}
</style>
""", unsafe_allow_html=True)
# Initialize session state variables if not already set
if 'input_text' not in st.session_state:
st.session_state.input_text = ""
if 'summary' not in st.session_state:
st.session_state.summary = ""
if 'main_points' not in st.session_state:
st.session_state.main_points = ""
if 'flashcards' not in st.session_state:
st.session_state.flashcards = ""
# Display the title and introduction
st.title("InsightStarfleet")
st.write("""
Welcome to the InsightStarfleet! This application helps you process text by summarizing content,
extracting main points, and creating flashcards. Follow the instructions to enter your text and generate content.
""")
# Input area for text
st.subheader("Enter Your Text")
input_text = st.text_area(
label="Enter text below:",
value=st.session_state.input_text,
height=200,
key="input_text",
help="Paste or type your text here for processing."
)
# Update session state if input text changes
if input_text != st.session_state.input_text:
st.session_state.input_text = input_text
# Text Processing
st.subheader("Text Processing")
if st.session_state.input_text:
# Caching API call function
@st.cache_data
def generate_response(system_message, user_message):
response = _generate_response(system_message, user_message)
# Strip any unwanted labels or text
return response.strip()
# Buttons for processing
if st.button("Generate Summary"):
summary_prompt = "Summarize the following text into a brief summary:"
st.session_state.summary = generate_response(summary_prompt, st.session_state.input_text)
if st.button("Extract Main Points"):
main_points_prompt = "Extract the main points from the following text and format them as a bulleted list:"
st.session_state.main_points = generate_response(main_points_prompt, st.session_state.input_text)
if st.button("Generate Flashcards"):
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]':"
st.session_state.flashcards = generate_response(flashcards_prompt, st.session_state.input_text)
else:
# Only show generate buttons if text is present
if st.button("Generate Summary") or st.button("Extract Main Points") or st.button("Generate Flashcards"):
st.error("Please enter text before generating content.")
# Combined Results
st.subheader("Results")
# Summary
if st.session_state.summary:
st.markdown("### Summary")
st.text_area(
"Summary",
value=st.session_state.summary,
height=200,
key="summary_results",
help="Generated summary."
)
st.download_button(
label="Download Summary",
data=st.session_state.summary,
file_name="summary.txt",
mime="text/plain"
)
# Main Points
if st.session_state.main_points:
st.markdown("### Main Points")
# Remove any leading or trailing blank lines from main points
bullet_points = "\n".join([f"- {point.strip()}" for point in st.session_state.main_points.split("\n") if point.strip()])
st.markdown(f"### Main Points\n{bullet_points}", unsafe_allow_html=True)
st.download_button(
label="Download Main Points",
data=bullet_points,
file_name="main_points.txt",
mime="text/plain"
)
|