Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
|
| 124 |
# Subject selection
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 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
|
| 140 |
-
|
| 141 |
-
if
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
else:
|
| 146 |
-
st.
|
| 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:
|