Spaces:
Sleeping
Sleeping
themanas021
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -10,10 +10,11 @@ import chromadb
|
|
10 |
chromadb.api.client.SharedSystemClient.clear_system_cache()
|
11 |
|
12 |
import os
|
13 |
-
os.environ["OPENAI_API_KEY"]=os.getenv('OPENAI_API_KEY')
|
|
|
14 |
# Initialize the embeddings and model
|
15 |
embd = OpenAIEmbeddings()
|
16 |
-
llm = ChatOpenAI(model_name="gpt-
|
17 |
|
18 |
# Initialize conversation history
|
19 |
if "conversation_history" not in st.session_state:
|
@@ -60,29 +61,29 @@ if uploaded_file:
|
|
60 |
query = st.text_input("Ask a question:")
|
61 |
|
62 |
if query:
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
st.write(f"**Source {i}:** {doc.metadata.get('source', 'Unknown Source')}")
|
78 |
-
st.write(doc.page_content[:500]) # Display the first 500 characters of the source content
|
79 |
-
|
80 |
-
# Display conversation history
|
81 |
-
st.subheader("Conversation History")
|
82 |
-
for idx, (q, a, s) in enumerate(st.session_state.conversation_history, 1):
|
83 |
-
st.write(f"**Q{idx}:** {q}")
|
84 |
-
st.write(f"**A{idx}:** {a}")
|
85 |
-
st.write(f"**Sources for Q{idx}:**")
|
86 |
-
for i, doc in enumerate(s, start=1):
|
87 |
st.write(f"**Source {i}:** {doc.metadata.get('source', 'Unknown Source')}")
|
88 |
-
st.write(doc.page_content[:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
chromadb.api.client.SharedSystemClient.clear_system_cache()
|
11 |
|
12 |
import os
|
13 |
+
os.environ["OPENAI_API_KEY"] = os.getenv('OPENAI_API_KEY')
|
14 |
+
|
15 |
# Initialize the embeddings and model
|
16 |
embd = OpenAIEmbeddings()
|
17 |
+
llm = ChatOpenAI(model_name="gpt-4o", temperature=0)
|
18 |
|
19 |
# Initialize conversation history
|
20 |
if "conversation_history" not in st.session_state:
|
|
|
61 |
query = st.text_input("Ask a question:")
|
62 |
|
63 |
if query:
|
64 |
+
# Process the query
|
65 |
+
result = qa_chain({"query": query})
|
66 |
+
answer = result["result"]
|
67 |
+
sources = result["source_documents"]
|
68 |
+
|
69 |
+
# Append to conversation history
|
70 |
+
st.session_state.conversation_history.append((query, answer, sources))
|
71 |
+
|
72 |
+
# Display the current answer
|
73 |
+
st.write("**Answer:**", answer)
|
74 |
+
|
75 |
+
# Display the sources
|
76 |
+
st.subheader("Source Documents")
|
77 |
+
for i, doc in enumerate(sources, start=1):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
st.write(f"**Source {i}:** {doc.metadata.get('source', 'Unknown Source')}")
|
79 |
+
st.write(doc.page_content[:500]) # Display the first 500 characters of the source content
|
80 |
+
|
81 |
+
# Display conversation history
|
82 |
+
st.subheader("Conversation History")
|
83 |
+
for idx, (q, a, s) in enumerate(st.session_state.conversation_history, 1):
|
84 |
+
st.write(f"**Q{idx}:** {q}")
|
85 |
+
st.write(f"**A{idx}:** {a}")
|
86 |
+
st.write(f"**Sources for Q{idx}:**")
|
87 |
+
for i, doc in enumerate(s, start=1):
|
88 |
+
st.write(f"**Source {i}:** {doc.metadata.get('source', 'Unknown Source')}")
|
89 |
+
st.write(doc.page_content[:300]) # Show a snippet for brevity
|