Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -112,32 +112,32 @@ submit = st.button("Submit")
|
|
| 112 |
|
| 113 |
if submit:
|
| 114 |
if openai_api_key:
|
| 115 |
-
try:
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
except:
|
| 143 |
-
|
|
|
|
| 112 |
|
| 113 |
if submit:
|
| 114 |
if openai_api_key:
|
| 115 |
+
# try:
|
| 116 |
+
client = OpenAI(api_key=openai_api_key)
|
| 117 |
+
if uploaded_files:
|
| 118 |
+
textify_output = read_and_textify_advanced(uploaded_files, sentence_chunks)
|
| 119 |
+
|
| 120 |
+
df = pd.DataFrame(textify_output)
|
| 121 |
+
df.columns = ['context']
|
| 122 |
+
|
| 123 |
+
if question_protocol == "":
|
| 124 |
+
question_protocol = "Write questions based on the text"
|
| 125 |
+
df['questions'] = df.apply(lambda row: get_questions(row['context'], question_protocol), axis=1)
|
| 126 |
+
|
| 127 |
+
if answer_protocol == "":
|
| 128 |
+
answer_protocol = "Write answers based on the text"
|
| 129 |
+
df['answers'] = df.apply(lambda row: get_answers(row, answer_protocol), axis=1)
|
| 130 |
+
|
| 131 |
+
df = df.drop['context']
|
| 132 |
+
|
| 133 |
+
csv = df.to_csv(index=False).encode('utf-8')
|
| 134 |
+
st.download_button(
|
| 135 |
+
label="Download Q/A pairs as CSV",
|
| 136 |
+
data=csv,
|
| 137 |
+
file_name='questions_answers.csv',
|
| 138 |
+
mime='text/csv',
|
| 139 |
+
)
|
| 140 |
+
else:
|
| 141 |
+
st.error("Please upload at least 1 PDF")
|
| 142 |
+
# except:
|
| 143 |
+
# st.error("OpenAI API key is invalid")
|