Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -118,45 +118,52 @@ def main():
|
|
118 |
if "vectorstore" not in st.session_state:
|
119 |
st.session_state.vectorstore = None
|
120 |
|
121 |
-
#
|
122 |
-
|
123 |
-
|
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:",
|
130 |
-
selected_folder = content_types[content_type]
|
131 |
|
132 |
-
#
|
133 |
-
if
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
137 |
|
|
|
138 |
selected_subject = st.sidebar.selectbox("Select a Subject:", subjects)
|
139 |
|
140 |
-
# Process
|
141 |
raw_text = ""
|
142 |
-
if selected_subject:
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
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:
|
157 |
st.subheader("Preview of Notes")
|
158 |
st.text_area("Preview Content:", value=raw_text[:2000], height=300, disabled=True) # Show a snippet of the notes
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
# Chat interface
|
161 |
st.subheader("Ask Your Question")
|
162 |
question = st.text_input("Ask a question about your selected subject:")
|
|
|
118 |
if "vectorstore" not in st.session_state:
|
119 |
st.session_state.vectorstore = None
|
120 |
|
121 |
+
# Define folders for Current Affairs and Essays
|
122 |
+
data_folder = "data"
|
123 |
+
essay_folder = "essay"
|
|
|
|
|
|
|
124 |
|
125 |
# Content type selection
|
126 |
+
content_type = st.sidebar.radio("Select Content Type:", ["Current Affairs", "Essays"])
|
|
|
127 |
|
128 |
+
# Handle Current Affairs (each subject has its own folder)
|
129 |
+
if content_type == "Current Affairs":
|
130 |
+
if os.path.exists(data_folder):
|
131 |
+
subjects = [f for f in os.listdir(data_folder) if os.path.isdir(os.path.join(data_folder, f))]
|
132 |
+
else:
|
133 |
+
subjects = []
|
134 |
+
# Handle Essays (all essays are in a single folder)
|
135 |
+
elif content_type == "Essays":
|
136 |
+
if os.path.exists(essay_folder):
|
137 |
+
subjects = [f.replace(".txt", "") for f in os.listdir(essay_folder) if f.endswith('.txt')]
|
138 |
+
else:
|
139 |
+
subjects = []
|
140 |
|
141 |
+
# Subject selection
|
142 |
selected_subject = st.sidebar.selectbox("Select a Subject:", subjects)
|
143 |
|
144 |
+
# Process selected subject
|
145 |
raw_text = ""
|
146 |
+
if content_type == "Current Affairs" and selected_subject:
|
147 |
+
subject_folder = os.path.join(data_folder, selected_subject)
|
148 |
+
raw_text = get_text_files_content(subject_folder)
|
149 |
+
elif content_type == "Essays" and selected_subject:
|
150 |
+
subject_file = os.path.join(essay_folder, selected_subject + ".txt")
|
151 |
+
if os.path.exists(subject_file):
|
152 |
+
with open(subject_file, "r", encoding="utf-8") as file:
|
153 |
+
raw_text = file.read()
|
|
|
|
|
|
|
|
|
154 |
|
155 |
# Display preview of notes
|
156 |
if raw_text:
|
157 |
st.subheader("Preview of Notes")
|
158 |
st.text_area("Preview Content:", value=raw_text[:2000], height=300, disabled=True) # Show a snippet of the notes
|
159 |
|
160 |
+
# Create vectorstore for Current Affairs or Essays
|
161 |
+
text_chunks = get_chunks(raw_text)
|
162 |
+
vectorstore = get_vectorstore(text_chunks)
|
163 |
+
st.session_state.vectorstore = vectorstore
|
164 |
+
else:
|
165 |
+
st.warning("No content available for the selected subject.")
|
166 |
+
|
167 |
# Chat interface
|
168 |
st.subheader("Ask Your Question")
|
169 |
question = st.text_input("Ask a question about your selected subject:")
|