danishjameel003 commited on
Commit
51fcb96
·
verified ·
1 Parent(s): d5b93a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -21
app.py CHANGED
@@ -118,34 +118,39 @@ def main():
118
  if "vectorstore" not in st.session_state:
119
  st.session_state.vectorstore = None
120
 
121
- # Folder for subject data
122
- data_folder = "data"
 
 
 
 
 
 
 
 
123
 
124
  # Subject selection
125
- subjects = [
126
- "A Trumped World", "Agri Tax in Punjab", "Assad's Fall in Syria", "Elusive National Unity", "Europe and Trump 2.0",
127
- "Going Down with Democracy", "Indonesia's Pancasila Philosophy", "Pakistan in Choppy Waters",
128
- "Pakistan's Semiconductor Ambitions", "Preserving Pakistan's Cultural Heritage", "Tackling Informal Economy",
129
- "Technical Education in Pakistan", "The Case for Solidarity Levies", "The Decline of the Sole Superpower",
130
- "The Power of Big Oil", "Trump 2.0 and Pakistan's Emerging Foreign Policy", "Trump and the World 2.0",
131
- "Trump vs BRICS", "US-China Trade War", "War on Humanity", "Women's Suppression in Afghanistan"
132
- ]
133
- subject_folders = {subject: os.path.join(data_folder, subject.replace(' ', '_')) for subject in subjects}
134
  selected_subject = st.sidebar.selectbox("Select a Subject:", subjects)
135
 
136
  # Process data folder for vectorstore
137
- subject_folder_path = subject_folders[selected_subject]
138
  raw_text = ""
139
- if os.path.exists(subject_folder_path):
140
- raw_text = get_text_files_content(subject_folder_path)
141
- if raw_text:
142
- text_chunks = get_chunks(raw_text)
143
- vectorstore = get_vectorstore(text_chunks)
144
- st.session_state.vectorstore = vectorstore
 
 
 
 
145
  else:
146
- st.warning("No content found for the selected subject.")
147
- else:
148
- st.error(f"Folder not found for {selected_subject}.")
149
 
150
  # Display preview of notes
151
  if raw_text:
 
118
  if "vectorstore" not in st.session_state:
119
  st.session_state.vectorstore = None
120
 
121
+ # Root folder for content
122
+ root_folder = "data"
123
+ content_types = {
124
+ "Current Affairs": os.path.join(root_folder, "current_affairs"),
125
+ "Essays": os.path.join(root_folder, "essays")
126
+ }
127
+
128
+ # Content type selection
129
+ content_type = st.sidebar.radio("Select Content Type:", list(content_types.keys()))
130
+ selected_folder = content_types[content_type]
131
 
132
  # Subject selection
133
+ if os.path.exists(selected_folder):
134
+ subjects = [f.replace("_", " ").replace(".txt", "") for f in os.listdir(selected_folder) if f.endswith('.txt')]
135
+ else:
136
+ subjects = []
137
+
 
 
 
 
138
  selected_subject = st.sidebar.selectbox("Select a Subject:", subjects)
139
 
140
  # Process data folder for vectorstore
 
141
  raw_text = ""
142
+ if selected_subject:
143
+ subject_path = os.path.join(selected_folder, selected_subject.replace(" ", "_") + ".txt")
144
+ if os.path.exists(subject_path):
145
+ raw_text = get_text_files_content(selected_folder)
146
+ if raw_text:
147
+ text_chunks = get_chunks(raw_text)
148
+ vectorstore = get_vectorstore(text_chunks)
149
+ st.session_state.vectorstore = vectorstore
150
+ else:
151
+ st.warning("No content found for the selected subject.")
152
  else:
153
+ st.error(f"File not found for {selected_subject}.")
 
 
154
 
155
  # Display preview of notes
156
  if raw_text: