Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
import tempfile
|
3 |
from dspy_qa import DocQA
|
4 |
-
import os
|
5 |
-
os.system("pip install dspy-ai[faiss-cpu]")
|
6 |
|
7 |
st.set_page_config(page_title="DoC QA", layout="wide")
|
8 |
# st.title("π Chat over PDF using DSPy π")
|
@@ -48,9 +47,9 @@ if "knowledge_base" not in st.session_state:
|
|
48 |
st.session_state.knowledge_base = None
|
49 |
|
50 |
if st.session_state.knowledge_base is None:
|
51 |
-
pdf_file = st.file_uploader("Upload a PDF file", "
|
52 |
if pdf_file:
|
53 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".
|
54 |
temp_file.write(pdf_file.getbuffer())
|
55 |
temp_file_path = temp_file.name
|
56 |
docqa = DocQA(temp_file_path)
|
@@ -79,11 +78,11 @@ if question := st.chat_input("What is up?"):
|
|
79 |
# Display user message in chat message container
|
80 |
with st.chat_message("user"):
|
81 |
st.markdown(question)
|
82 |
-
|
83 |
if docqa is None:
|
84 |
with st.chat_message("assistant"):
|
85 |
st.markdown("Please upload a PDF file first.")
|
86 |
-
st.session_state.messages.append({"role": "assistant", "content": "Please upload a PDF file first
|
87 |
st.stop()
|
88 |
# Display assistant response in chat message container
|
89 |
with st.chat_message("assistant"):
|
|
|
1 |
+
%%writefile app.py
|
2 |
import streamlit as st
|
3 |
import tempfile
|
4 |
from dspy_qa import DocQA
|
|
|
|
|
5 |
|
6 |
st.set_page_config(page_title="DoC QA", layout="wide")
|
7 |
# st.title("π Chat over PDF using DSPy π")
|
|
|
47 |
st.session_state.knowledge_base = None
|
48 |
|
49 |
if st.session_state.knowledge_base is None:
|
50 |
+
pdf_file = st.file_uploader("Upload a PDF file", "pdf")
|
51 |
if pdf_file:
|
52 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as temp_file:
|
53 |
temp_file.write(pdf_file.getbuffer())
|
54 |
temp_file_path = temp_file.name
|
55 |
docqa = DocQA(temp_file_path)
|
|
|
78 |
# Display user message in chat message container
|
79 |
with st.chat_message("user"):
|
80 |
st.markdown(question)
|
81 |
+
|
82 |
if docqa is None:
|
83 |
with st.chat_message("assistant"):
|
84 |
st.markdown("Please upload a PDF file first.")
|
85 |
+
st.session_state.messages.append({"role": "assistant", "content": "Please upload a PDF file first."})
|
86 |
st.stop()
|
87 |
# Display assistant response in chat message container
|
88 |
with st.chat_message("assistant"):
|