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