File size: 3,220 Bytes
08a0246
9f8a212
 
f1e900a
08a0246
 
f1e900a
9f8a212
 
f1e900a
08a0246
9f8a212
fcc56dc
 
9f8a212
08a0246
 
9f8a212
 
 
 
fcc56dc
9f8a212
 
 
 
fcc56dc
 
 
 
9f8a212
 
 
 
 
 
 
 
 
fcc56dc
9f8a212
 
 
 
fcc56dc
9f8a212
 
 
fcc56dc
9f8a212
 
 
 
 
fcc56dc
9f8a212
 
 
fcc56dc
9f8a212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
    @st.cache_data
    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"
    )