Makima57 commited on
Commit
22bfc32
1 Parent(s): ca30905

Update chat_with_doc.py

Browse files
Files changed (1) hide show
  1. chat_with_doc.py +3 -5
chat_with_doc.py CHANGED
@@ -1,7 +1,6 @@
1
  import os
2
  import openai
3
  import streamlit as st
4
- import json
5
 
6
  # Load environment variables
7
  from dotenv import load_dotenv
@@ -25,10 +24,10 @@ def get_openai_response(prompt, model="gpt-4", max_tokens=150):
25
  # Streamlit UI
26
  st.title("Chat with Your Document")
27
 
28
- # Load chunked data from the file (chunked_data.json)
29
  try:
30
- with open("chunked_data.json", "r") as f:
31
- chunked_data = json.load(f)
32
  st.write("Document has been chunked into the following parts:")
33
  for i, chunk_part in enumerate(chunked_data, 1):
34
  st.write(f"**Chunk {i}:**\n{chunk_part}\n")
@@ -48,4 +47,3 @@ if st.button("Get Answer"):
48
  st.write(f"**Answer**: {response}")
49
  else:
50
  st.error("Please provide a question.")
51
-
 
1
  import os
2
  import openai
3
  import streamlit as st
 
4
 
5
  # Load environment variables
6
  from dotenv import load_dotenv
 
24
  # Streamlit UI
25
  st.title("Chat with Your Document")
26
 
27
+ # Load chunked data from the .txt file (chunked_data.txt)
28
  try:
29
+ with open("chunked_data.txt", "r") as f:
30
+ chunked_data = f.read().split("\n---\n") # Split by delimiter to separate chunks
31
  st.write("Document has been chunked into the following parts:")
32
  for i, chunk_part in enumerate(chunked_data, 1):
33
  st.write(f"**Chunk {i}:**\n{chunk_part}\n")
 
47
  st.write(f"**Answer**: {response}")
48
  else:
49
  st.error("Please provide a question.")