Spaces:
Sleeping
Sleeping
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") | |
# Define the tabs | |
tab1, tab2, tab3, tab4, tab5 = st.tabs(["Introduction", "Text Processing", "Summary & Main Points", "Flashcards", "Results"]) | |
with tab1: | |
st.write(""" | |
Welcome to the AI71 Text Processing Tool! 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. | |
""") | |
with tab2: | |
AI71_API_KEY = get_ai71_api_key() | |
st.title("Text Processing") | |
# Initialize session state variables | |
session_vars = ['input_text', 'summary', 'main_points', 'flashcards', 'results'] | |
for var in session_vars: | |
if var not in st.session_state: | |
st.session_state[var] = "" | |
st.subheader("Enter Your Text") | |
# Input area for text | |
st.session_state.input_text = st.text_area("Enter text below:", height=200) | |
# Caching API call function | |
def generate_response(system_message, user_message): | |
return _generate_response(system_message, user_message) | |
with tab3: | |
st.title("Summary & Main Points") | |
if st.session_state.input_text: | |
summary_prompt = "Summarize the following text into a brief summary:" | |
main_points_prompt = "Extract the main points from the following text:" | |
if st.button("Generate Summary"): | |
st.session_state.summary = generate_response(summary_prompt, st.session_state.input_text) | |
st.text_area("Summary", value=st.session_state.summary, height=200, key="summary") | |
if st.button("Extract Main Points"): | |
st.session_state.main_points = generate_response(main_points_prompt, st.session_state.input_text) | |
st.text_area("Main Points", value=st.session_state.main_points, height=200, key="main_points") | |
with tab4: | |
st.title("Flashcards") | |
if st.session_state.input_text: | |
flashcards_prompt = "Create flashcards with questions and answers based on the following text:" | |
if st.button("Generate Flashcards"): | |
st.session_state.flashcards = generate_response(flashcards_prompt, st.session_state.input_text) | |
st.text_area("Flashcards", value=st.session_state.flashcards, height=200, key="flashcards") | |
with tab5: | |
st.title("Results") | |
st.subheader("Summary") | |
st.text_area("Summary", value=st.session_state.summary, height=200, key="summary_results") | |
st.subheader("Main Points") | |
st.text_area("Main Points", value=st.session_state.main_points, height=200, key="main_points_results") | |
st.subheader("Flashcards") | |
st.text_area("Flashcards", value=st.session_state.flashcards, height=200, key="flashcards_results") | |
st.subheader("Download Results") | |
results = f"Summary:\n{st.session_state.summary}\n\nMain Points:\n{st.session_state.main_points}\n\nFlashcards:\n{st.session_state.flashcards}" | |
st.download_button( | |
label="Download Results", | |
data=results, | |
file_name="results.txt", | |
mime="text/plain" | |
) | |