Spaces:
Runtime error
Runtime error
added OPENAI_API_KEY
Browse filesllama_index GPTVectorStoreIndex uses LLM implicitly, so OPENAI_API_KEY is added
- .vscode/settings.json +6 -0
- app.py +19 -16
- tmp_docs/1.txt +1 -0
- tmp_docs/2.txt +1 -0
.vscode/settings.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"[python]": {
|
3 |
+
"editor.defaultFormatter": "ms-python.autopep8"
|
4 |
+
},
|
5 |
+
"python.formatting.provider": "none"
|
6 |
+
}
|
app.py
CHANGED
@@ -43,25 +43,28 @@ def query(index, query_text):
|
|
43 |
return response
|
44 |
|
45 |
|
46 |
-
|
47 |
-
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
save_file(files)
|
53 |
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
index = ingest('tmp_docs')
|
56 |
|
57 |
-
# Display message input component
|
58 |
-
message = st.text_input('Enter message')
|
59 |
|
60 |
-
# If message is entered, ingest documents and get chatbot response
|
61 |
-
if message:
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
# Display chat history
|
66 |
-
st.text_area('Chatbot:', value='\n'.join(
|
67 |
-
|
|
|
43 |
return response
|
44 |
|
45 |
|
46 |
+
os.environ['OPENAI_API_KEY'] = st.text_input(
|
47 |
+
"Enter your OpenAI API key", type="password")
|
48 |
|
49 |
+
if os.environ['OPENAI_API_KEY']:
|
50 |
+
# Initialize chatbot history
|
51 |
+
chatbot = []
|
|
|
52 |
|
53 |
+
# Display file upload component
|
54 |
+
files = st.file_uploader('Upload Files', accept_multiple_files=True)
|
55 |
+
if files is not None:
|
56 |
+
save_file(files)
|
57 |
|
58 |
+
index = ingest('tmp_docs')
|
59 |
|
60 |
+
# Display message input component
|
61 |
+
message = st.text_input('Enter message')
|
62 |
|
63 |
+
# If message is entered, ingest documents and get chatbot response
|
64 |
+
if message:
|
65 |
+
chatbot.append(('You', message))
|
66 |
+
chatbot += get_answer(index, message)
|
67 |
|
68 |
+
# Display chat history
|
69 |
+
st.text_area('Chatbot:', value='\n'.join(
|
70 |
+
[f'{x[0]}: {x[1]}' for x in chatbot]), height=250)
|
tmp_docs/1.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Bob says: 1+1=1
|
tmp_docs/2.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Carol says: 1+1=2
|