Spaces:
Sleeping
Sleeping
mehradans92
commited on
Commit
•
b6f12dc
1
Parent(s):
409f045
got it to work :)
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ import time
|
|
9 |
import shutil
|
10 |
|
11 |
import pickle
|
12 |
-
|
13 |
|
14 |
#title
|
15 |
st.title("Encode knowledge from papers with cited references")
|
@@ -23,6 +23,7 @@ api_key = st.text_input('OpenAI API Key',
|
|
23 |
type="password")
|
24 |
|
25 |
# st.write('The current movie title is', title)
|
|
|
26 |
os.environ["OPENAI_API_KEY"] = f"{api_key}" #
|
27 |
import paperqa
|
28 |
|
@@ -129,12 +130,13 @@ def download_pdf(pdf_info):
|
|
129 |
|
130 |
max_results_current = 1
|
131 |
max_results = max_results_current
|
132 |
-
pdf_info = ''
|
133 |
-
pdf_citation = ''
|
134 |
def search_click_callback(search_query, max_results):
|
135 |
global pdf_info, pdf_citation
|
136 |
pdf_info, pdf_citation = call_arXiv_API(f'{search_query}', max_results=max_results)
|
137 |
download_pdf(pdf_info)
|
|
|
138 |
|
139 |
|
140 |
|
@@ -142,7 +144,7 @@ def search_click_callback(search_query, max_results):
|
|
142 |
with st.form(key='columns_in_form', clear_on_submit = False):
|
143 |
c1, c2 = st.columns([8,1])
|
144 |
with c1:
|
145 |
-
search_query = st.text_input("Input search query here:", placeholder='Keywords for most relevant search...', value=''
|
146 |
)#search_query, max_results_current))
|
147 |
|
148 |
with c2:
|
@@ -152,22 +154,23 @@ with st.form(key='columns_in_form', clear_on_submit = False):
|
|
152 |
# search_click(search_query, max_results_default)
|
153 |
|
154 |
if searchButton:
|
155 |
-
|
|
|
|
|
|
|
|
|
156 |
|
157 |
-
def tokenize_callback():
|
158 |
-
global docs
|
159 |
-
docs = paperqa.Docs()
|
160 |
-
pdf_paths = [f"{p[4]}/{p[0]}.pdf" for p in pdf_info]
|
161 |
-
pdf_citations = [p[5] for p in pdf_info]
|
162 |
|
163 |
-
|
164 |
-
|
165 |
# return docs
|
166 |
|
167 |
-
tokenization_form = st.form(key='tokenization-form')
|
168 |
-
tokenization_form.markdown(f"Happy with your paper search results? ")
|
169 |
-
toknizeButton = tokenization_form.form_submit_button(label = "Yes! Let's tokenize.", on_click=tokenize_callback())
|
170 |
-
tokenization_form.markdown("If not, change keywords and search again. [This step costs!](https://openai.com/api/pricing/)")
|
|
|
|
|
171 |
|
172 |
# submitButton = form.form_submit_button('Submit')
|
173 |
# with st.form(key='tokenization_form', clear_on_submit = False):
|
@@ -179,18 +182,34 @@ tokenization_form.markdown("If not, change keywords and search again. [This step
|
|
179 |
# if toknizeButton:
|
180 |
# tokenize_callback()
|
181 |
|
|
|
|
|
182 |
def answer_callback(question_query):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
answer = docs.query(question_query)
|
184 |
print(answer.formatted_answer)
|
185 |
return answer.formatted_answer
|
186 |
|
187 |
form = st.form(key='question_form')
|
188 |
question_query = form.text_input("What do you wanna know from these papers?", placeholder='Input questions here...',
|
189 |
-
value='')
|
190 |
submitButton = form.form_submit_button('Submit')
|
191 |
|
192 |
if submitButton:
|
193 |
-
text = st.text_area("Answer:", answer_callback(question_query), height=
|
194 |
|
195 |
# with st.form(key='question_form', clear_on_submit = False):
|
196 |
# question_query = st.text_input("What do you wanna know from these papers?", placeholder='Input questions here')
|
|
|
9 |
import shutil
|
10 |
|
11 |
import pickle
|
12 |
+
docs = None
|
13 |
|
14 |
#title
|
15 |
st.title("Encode knowledge from papers with cited references")
|
|
|
23 |
type="password")
|
24 |
|
25 |
# st.write('The current movie title is', title)
|
26 |
+
api_key = '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'
|
27 |
os.environ["OPENAI_API_KEY"] = f"{api_key}" #
|
28 |
import paperqa
|
29 |
|
|
|
130 |
|
131 |
max_results_current = 1
|
132 |
max_results = max_results_current
|
133 |
+
# pdf_info = ''
|
134 |
+
# pdf_citation = ''
|
135 |
def search_click_callback(search_query, max_results):
|
136 |
global pdf_info, pdf_citation
|
137 |
pdf_info, pdf_citation = call_arXiv_API(f'{search_query}', max_results=max_results)
|
138 |
download_pdf(pdf_info)
|
139 |
+
return pdf_info
|
140 |
|
141 |
|
142 |
|
|
|
144 |
with st.form(key='columns_in_form', clear_on_submit = False):
|
145 |
c1, c2 = st.columns([8,1])
|
146 |
with c1:
|
147 |
+
search_query = st.text_input("Input search query here:", placeholder='Keywords for most relevant search...', value='CFD modeling'
|
148 |
)#search_query, max_results_current))
|
149 |
|
150 |
with c2:
|
|
|
154 |
# search_click(search_query, max_results_default)
|
155 |
|
156 |
if searchButton:
|
157 |
+
global pdf_info
|
158 |
+
pdf_info = search_click_callback(search_query, max_results)
|
159 |
+
if 'pdf_info' not in st.session_state:
|
160 |
+
st.session_state['pdf_info'] = pdf_info
|
161 |
+
print(f'This is PDF info from search:{pdf_info}')
|
162 |
|
|
|
|
|
|
|
|
|
|
|
163 |
|
164 |
+
# def tokenize_callback():
|
165 |
+
|
166 |
# return docs
|
167 |
|
168 |
+
# tokenization_form = st.form(key='tokenization-form')
|
169 |
+
# tokenization_form.markdown(f"Happy with your paper search results? ")
|
170 |
+
# toknizeButton = tokenization_form.form_submit_button(label = "Yes! Let's tokenize.", on_click=tokenize_callback())
|
171 |
+
# tokenization_form.markdown("If not, change keywords and search again. [This step costs!](https://openai.com/api/pricing/)")
|
172 |
+
|
173 |
+
|
174 |
|
175 |
# submitButton = form.form_submit_button('Submit')
|
176 |
# with st.form(key='tokenization_form', clear_on_submit = False):
|
|
|
182 |
# if toknizeButton:
|
183 |
# tokenize_callback()
|
184 |
|
185 |
+
# tokenize_callback()
|
186 |
+
|
187 |
def answer_callback(question_query):
|
188 |
+
global docs
|
189 |
+
# global pdf_info
|
190 |
+
if docs is None:
|
191 |
+
pdf_info = st.session_state['pdf_info']
|
192 |
+
print('buliding docs')
|
193 |
+
docs = paperqa.Docs()
|
194 |
+
pdf_paths = [f"{p[4]}/{p[0]}.pdf" for p in pdf_info]
|
195 |
+
pdf_citations = [p[5] for p in pdf_info]
|
196 |
+
print(list(zip(pdf_paths, pdf_citations)))
|
197 |
+
|
198 |
+
for d, c in stqdm(zip(pdf_paths, pdf_citations)):
|
199 |
+
print(d,c)
|
200 |
+
docs.add(d, c)
|
201 |
+
# docs._build_faiss_index()
|
202 |
answer = docs.query(question_query)
|
203 |
print(answer.formatted_answer)
|
204 |
return answer.formatted_answer
|
205 |
|
206 |
form = st.form(key='question_form')
|
207 |
question_query = form.text_input("What do you wanna know from these papers?", placeholder='Input questions here...',
|
208 |
+
value='Write 50 words on CFD modeling')
|
209 |
submitButton = form.form_submit_button('Submit')
|
210 |
|
211 |
if submitButton:
|
212 |
+
text = st.text_area("Answer:", answer_callback(question_query), height=600)
|
213 |
|
214 |
# with st.form(key='question_form', clear_on_submit = False):
|
215 |
# question_query = st.text_input("What do you wanna know from these papers?", placeholder='Input questions here')
|