Spaces:
Runtime error
Runtime error
fracapuano
commited on
Commit
·
0e17089
1
Parent(s):
a96d162
add: toward multiple files support
Browse files
qa/qa.py
CHANGED
@@ -3,7 +3,7 @@ from openai.error import OpenAIError
|
|
3 |
from .utils import *
|
4 |
from typing import Text, Union
|
5 |
|
6 |
-
multiple_files =
|
7 |
|
8 |
def clear_submit():
|
9 |
"""
|
@@ -52,18 +52,21 @@ def qa_main():
|
|
52 |
upload_document_greenlight = False
|
53 |
uploaded_processed_document_greenlight = False
|
54 |
# OpenAI API Key - TODO: consider adding a key valid for everyone
|
55 |
-
st.header("Configure OpenAI API Key")
|
56 |
-
st.warning('Please enter your OpenAI API Key!', icon='⚠️')
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
64 |
if user_secret:
|
65 |
if set_openai_api_key(user_secret):
|
66 |
-
st.success('OpenAI API key successfully
|
67 |
upload_document_greenlight = True
|
68 |
|
69 |
if upload_document_greenlight:
|
@@ -74,18 +77,22 @@ def qa_main():
|
|
74 |
type=["pdf", "docx", "txt", "py", "json", "html", "css", "md"],
|
75 |
help="Scanned documents are not supported yet 🥲",
|
76 |
on_change=clear_submit,
|
77 |
-
accept_multiple_files=multiple_files
|
78 |
)
|
79 |
|
80 |
-
# reading the uploaded
|
81 |
-
|
|
|
82 |
# toggle internal file submission state to True
|
83 |
st.session_state["file_submitted"] = True
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
|
|
|
|
|
|
89 |
try:
|
90 |
with st.spinner("Indexing the document... This might take a while!"):
|
91 |
index = embed_docs(tuple(text))
|
|
|
3 |
from .utils import *
|
4 |
from typing import Text, Union
|
5 |
|
6 |
+
multiple_files = True
|
7 |
|
8 |
def clear_submit():
|
9 |
"""
|
|
|
52 |
upload_document_greenlight = False
|
53 |
uploaded_processed_document_greenlight = False
|
54 |
# OpenAI API Key - TODO: consider adding a key valid for everyone
|
55 |
+
# st.header("Configure OpenAI API Key")
|
56 |
+
# st.warning('Please enter your OpenAI API Key!', icon='⚠️')
|
57 |
+
|
58 |
+
# uncomment the following lines to add a user-specific key
|
59 |
+
# user_secret = st.text_input(
|
60 |
+
# "Insert your OpenAI API key here ([get your API key](https://platform.openai.com/account/api-keys)).",
|
61 |
+
# type="password",
|
62 |
+
# placeholder="Paste your OpenAI API key here (sk-...)",
|
63 |
+
# help="You can get your API key from https://platform.openai.com/account/api-keys.",
|
64 |
+
# value=st.session_state.get("OPENAI_API_KEY", ""),
|
65 |
+
# )
|
66 |
+
user_secret = st.secrets["OPENAI_API_KEY"]
|
67 |
if user_secret:
|
68 |
if set_openai_api_key(user_secret):
|
69 |
+
st.success('OpenAI API key successfully accessed!', icon='✅')
|
70 |
upload_document_greenlight = True
|
71 |
|
72 |
if upload_document_greenlight:
|
|
|
77 |
type=["pdf", "docx", "txt", "py", "json", "html", "css", "md"],
|
78 |
help="Scanned documents are not supported yet 🥲",
|
79 |
on_change=clear_submit,
|
80 |
+
accept_multiple_files=multiple_files
|
81 |
)
|
82 |
|
83 |
+
# reading the uploaded files
|
84 |
+
text = []
|
85 |
+
if len(uploaded_file) != 0:
|
86 |
# toggle internal file submission state to True
|
87 |
st.session_state["file_submitted"] = True
|
88 |
+
for file in uploaded_file:
|
89 |
+
# parse the file using custom parsers
|
90 |
+
file_doc = file_to_doc(file)
|
91 |
+
# converts the files into a list of documents
|
92 |
+
file_text = text_to_docs(text=tuple(file_doc), file_name=file.name)
|
93 |
+
text.extend(file_text)
|
94 |
+
|
95 |
+
# embeds the documents using OpenAI API
|
96 |
try:
|
97 |
with st.spinner("Indexing the document... This might take a while!"):
|
98 |
index = embed_docs(tuple(text))
|