iqra785 commited on
Commit
7b22dde
·
verified ·
1 Parent(s): 0020a82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -15
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 to style the page
9
  st.markdown("""
10
  <style>
11
  .main .block-container {
@@ -30,14 +30,23 @@ st.markdown("""
30
  margin: 0.5rem 0;
31
  background-color: #f9f9f9;
32
  }
 
 
 
 
 
33
  </style>
34
  """, unsafe_allow_html=True)
35
 
36
- # Initialize session state variables
37
- session_vars = ['input_text', 'summary', 'main_points', 'flashcards', 'results']
38
- for var in session_vars:
39
- if var not in st.session_state:
40
- st.session_state[var] = ""
 
 
 
 
41
 
42
  # Display the title and introduction
43
  st.title("AI71 Text Processing Tool")
@@ -48,7 +57,17 @@ st.write("""
48
 
49
  # Input area for text
50
  st.subheader("Enter Your Text")
51
- st.session_state.input_text = st.text_area("Enter text below:", height=200, key="input_text")
 
 
 
 
 
 
 
 
 
 
52
 
53
  # Text Processing
54
  if st.session_state.input_text:
@@ -68,9 +87,12 @@ if st.session_state.input_text:
68
  st.text_area("Summary", value=st.session_state.summary, height=200, key="summary", help="Summary of the input text.")
69
 
70
  if st.button("Extract Main Points"):
71
- main_points_prompt = "Extract the main points from the following text:"
72
  st.session_state.main_points = generate_response(main_points_prompt, st.session_state.input_text)
73
- st.text_area("Main Points", value=st.session_state.main_points, height=200, key="main_points", help="Main points extracted from the input text.")
 
 
 
74
 
75
  if st.button("Generate Flashcards"):
76
  flashcards_prompt = "Create flashcards with questions and answers based on the following text:"
@@ -93,14 +115,19 @@ if st.session_state.summary or st.session_state.main_points or st.session_state.
93
  st.text_area("Summary", value=st.session_state.summary, height=200, key="summary_results", help="Generated summary.")
94
 
95
  st.subheader("Main Points")
96
- st.text_area("Main Points", value=st.session_state.main_points, height=200, key="main_points_results", help="Extracted main points.")
 
 
97
 
98
  st.subheader("Flashcards")
99
- st.markdown("""
100
- <div class="flashcard">
101
- {flashcards}
102
- </div>
103
- """, unsafe_allow_html=True)
 
 
 
104
 
105
  st.subheader("Download Results")
106
  results = f"Summary:\n{st.session_state.summary}\n\nMain Points:\n{st.session_state.main_points}\n\nFlashcards:\n{st.session_state.flashcards}"
 
5
  # Set the page configuration to wide layout
6
  st.set_page_config(layout="wide")
7
 
8
+ # Custom CSS to style the page and text area
9
  st.markdown("""
10
  <style>
11
  .main .block-container {
 
30
  margin: 0.5rem 0;
31
  background-color: #f9f9f9;
32
  }
33
+ .stTextArea textarea {
34
+ font-size: 16px;
35
+ border-radius: 5px;
36
+ border: 2px solid #ddd;
37
+ }
38
  </style>
39
  """, unsafe_allow_html=True)
40
 
41
+ # Initialize session state variables if not already set
42
+ if 'input_text' not in st.session_state:
43
+ st.session_state.input_text = ""
44
+ if 'summary' not in st.session_state:
45
+ st.session_state.summary = ""
46
+ if 'main_points' not in st.session_state:
47
+ st.session_state.main_points = ""
48
+ if 'flashcards' not in st.session_state:
49
+ st.session_state.flashcards = ""
50
 
51
  # Display the title and introduction
52
  st.title("AI71 Text Processing Tool")
 
57
 
58
  # Input area for text
59
  st.subheader("Enter Your Text")
60
+ input_text = st.text_area(
61
+ label="Enter text below:",
62
+ value=st.session_state.input_text,
63
+ height=200,
64
+ key="input_text",
65
+ help="Paste or type your text here for processing."
66
+ )
67
+
68
+ # Update session state if input text changes
69
+ if input_text != st.session_state.input_text:
70
+ st.session_state.input_text = input_text
71
 
72
  # Text Processing
73
  if st.session_state.input_text:
 
87
  st.text_area("Summary", value=st.session_state.summary, height=200, key="summary", help="Summary of the input text.")
88
 
89
  if st.button("Extract Main Points"):
90
+ main_points_prompt = "Extract the main points from the following text and format them as a bulleted list:"
91
  st.session_state.main_points = generate_response(main_points_prompt, st.session_state.input_text)
92
+ # Format main points as a bulleted list
93
+ if st.session_state.main_points:
94
+ bullet_points = "\n".join([f"- {point.strip()}" for point in st.session_state.main_points.split("\n")])
95
+ st.markdown(f"### Main Points\n{bullet_points}", unsafe_allow_html=True)
96
 
97
  if st.button("Generate Flashcards"):
98
  flashcards_prompt = "Create flashcards with questions and answers based on the following text:"
 
115
  st.text_area("Summary", value=st.session_state.summary, height=200, key="summary_results", help="Generated summary.")
116
 
117
  st.subheader("Main Points")
118
+ if st.session_state.main_points:
119
+ bullet_points = "\n".join([f"- {point.strip()}" for point in st.session_state.main_points.split("\n")])
120
+ st.markdown(f"### Main Points\n{bullet_points}", unsafe_allow_html=True) # Displaying the main points as a bulleted list
121
 
122
  st.subheader("Flashcards")
123
+ if st.session_state.flashcards:
124
+ flashcards = st.session_state.flashcards.split("\n\n") # Assuming flashcards are separated by double newlines
125
+ for card in flashcards:
126
+ st.markdown(f"""
127
+ <div class="flashcard">
128
+ {card}
129
+ </div>
130
+ """, unsafe_allow_html=True)
131
 
132
  st.subheader("Download Results")
133
  results = f"Summary:\n{st.session_state.summary}\n\nMain Points:\n{st.session_state.main_points}\n\nFlashcards:\n{st.session_state.flashcards}"