Spaces:
Running
Running
Update interim.py
Browse files- interim.py +83 -16
interim.py
CHANGED
@@ -247,15 +247,41 @@ class DocumentRAG:
|
|
247 |
if "rag_system" not in st.session_state:
|
248 |
st.session_state.rag_system = DocumentRAG()
|
249 |
|
250 |
-
#
|
251 |
-
st.
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
256 |
|
257 |
-
#
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
uploaded_files = st.file_uploader("Upload files (PDF, TXT, CSV)", accept_multiple_files=True)
|
260 |
|
261 |
if st.button("Process Documents"):
|
@@ -269,25 +295,66 @@ if st.button("Process Documents"):
|
|
269 |
else:
|
270 |
st.warning("No files uploaded.")
|
271 |
|
272 |
-
#
|
273 |
-
st.subheader("Step 2:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
if st.session_state.rag_system.qa_chain:
|
275 |
history = []
|
276 |
user_question = st.text_input("Ask a question:")
|
277 |
if st.button("Submit Question"):
|
278 |
# Handle the user query
|
279 |
-
history = st.session_state.rag_system.handle_query(user_question, history)
|
280 |
for question, answer in history:
|
281 |
st.chat_message("user").write(question)
|
282 |
st.chat_message("assistant").write(answer)
|
283 |
else:
|
284 |
-
st.info("Please process documents
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
|
286 |
-
# Podcast Generation
|
287 |
-
st.subheader("Step 3: Generate Podcast")
|
288 |
if st.session_state.rag_system.document_summary:
|
289 |
if st.button("Generate Podcast"):
|
290 |
-
script, audio_path = st.session_state.rag_system.create_podcast()
|
291 |
if audio_path:
|
292 |
st.text_area("Generated Podcast Script", script, height=200)
|
293 |
st.audio(audio_path, format="audio/mp3")
|
@@ -295,4 +362,4 @@ if st.session_state.rag_system.document_summary:
|
|
295 |
else:
|
296 |
st.error(script)
|
297 |
else:
|
298 |
-
st.info("Please process documents
|
|
|
247 |
if "rag_system" not in st.session_state:
|
248 |
st.session_state.rag_system = DocumentRAG()
|
249 |
|
250 |
+
# Sidebar
|
251 |
+
with st.sidebar:
|
252 |
+
st.title("About")
|
253 |
+
st.markdown(
|
254 |
+
"""
|
255 |
+
This app is inspired by the [RAG_HW HuggingFace Space](https://huggingface.co/spaces/wint543/RAG_HW).
|
256 |
+
It allows users to upload documents, generate summaries, ask questions, and create podcasts.
|
257 |
+
"""
|
258 |
+
)
|
259 |
+
st.markdown("### Steps:")
|
260 |
+
st.markdown("1. Upload documents.")
|
261 |
+
st.markdown("2. Generate summaries.")
|
262 |
+
st.markdown("3. Ask questions.")
|
263 |
+
st.markdown("4. Create podcasts.")
|
264 |
|
265 |
+
# Streamlit UI
|
266 |
+
# Sidebar
|
267 |
+
#with st.sidebar:
|
268 |
+
#st.title("About")
|
269 |
+
#st.markdown(
|
270 |
+
#"""
|
271 |
+
#This app is inspired by the [RAG_HW HuggingFace Space](https://huggingface.co/spaces/wint543/RAG_HW).
|
272 |
+
#It allows users to:
|
273 |
+
#1. Upload and process documents
|
274 |
+
#2. Generate summaries
|
275 |
+
#3. Ask questions
|
276 |
+
#4. Create podcasts
|
277 |
+
#"""
|
278 |
+
#)
|
279 |
+
|
280 |
+
# Main App
|
281 |
+
st.title("Document Analyzer & Podcast Generator")
|
282 |
+
|
283 |
+
# Step 1: Upload and Process Documents
|
284 |
+
st.subheader("Step 1: Upload and Process Documents")
|
285 |
uploaded_files = st.file_uploader("Upload files (PDF, TXT, CSV)", accept_multiple_files=True)
|
286 |
|
287 |
if st.button("Process Documents"):
|
|
|
295 |
else:
|
296 |
st.warning("No files uploaded.")
|
297 |
|
298 |
+
# Step 2: Generate Summaries
|
299 |
+
st.subheader("Step 2: Generate Summaries")
|
300 |
+
st.write("Select Summary Language:")
|
301 |
+
summary_language_options = ["English", "Hindi", "Spanish", "French", "German", "Chinese", "Japanese"]
|
302 |
+
cols = st.columns(len(summary_language_options))
|
303 |
+
# Default selected option
|
304 |
+
summary_language = st.radio(
|
305 |
+
"",
|
306 |
+
summary_language_options,
|
307 |
+
horizontal=True,
|
308 |
+
key="summary_language"
|
309 |
+
)
|
310 |
+
|
311 |
+
if st.session_state.rag_system.document_summary:
|
312 |
+
st.text_area("Document Summary", st.session_state.rag_system.document_summary, height=200)
|
313 |
+
else:
|
314 |
+
st.info("Please process documents first to generate summaries.")
|
315 |
+
if st.button("Generate Summary"):
|
316 |
+
st.session_state.rag_system.document_summary = st.session_state.rag_system.generate_summary(
|
317 |
+
st.session_state.rag_system.document_summary,
|
318 |
+
summary_language
|
319 |
+
)
|
320 |
+
|
321 |
+
# Step 3: Ask Questions
|
322 |
+
st.subheader("Step 3: Ask Questions")
|
323 |
+
st.write("Select Q&A Language:")
|
324 |
+
qa_language_options = ["English", "Hindi", "Spanish", "French", "German", "Chinese", "Japanese"]
|
325 |
+
qa_language = st.radio(
|
326 |
+
"",
|
327 |
+
qa_language_options,
|
328 |
+
horizontal=True,
|
329 |
+
key="qa_language"
|
330 |
+
)
|
331 |
+
|
332 |
if st.session_state.rag_system.qa_chain:
|
333 |
history = []
|
334 |
user_question = st.text_input("Ask a question:")
|
335 |
if st.button("Submit Question"):
|
336 |
# Handle the user query
|
337 |
+
history = st.session_state.rag_system.handle_query(user_question, history, qa_language)
|
338 |
for question, answer in history:
|
339 |
st.chat_message("user").write(question)
|
340 |
st.chat_message("assistant").write(answer)
|
341 |
else:
|
342 |
+
st.info("Please process documents first to enable Q&A.")
|
343 |
+
|
344 |
+
# Step 4: Generate Podcast
|
345 |
+
st.subheader("Step 4: Generate Podcast")
|
346 |
+
st.write("Select Podcast Language:")
|
347 |
+
podcast_language_options = ["English", "Hindi", "Spanish", "French", "German", "Chinese", "Japanese"]
|
348 |
+
podcast_language = st.radio(
|
349 |
+
"",
|
350 |
+
podcast_language_options,
|
351 |
+
horizontal=True,
|
352 |
+
key="podcast_language"
|
353 |
+
)
|
354 |
|
|
|
|
|
355 |
if st.session_state.rag_system.document_summary:
|
356 |
if st.button("Generate Podcast"):
|
357 |
+
script, audio_path = st.session_state.rag_system.create_podcast(podcast_language)
|
358 |
if audio_path:
|
359 |
st.text_area("Generated Podcast Script", script, height=200)
|
360 |
st.audio(audio_path, format="audio/mp3")
|
|
|
362 |
else:
|
363 |
st.error(script)
|
364 |
else:
|
365 |
+
st.info("Please process documents and generate summaries before creating a podcast.")
|