Spaces:
Running
Running
update api details
Browse files- pages/1_paper_search.py +0 -1
- pages/3_qa_sources.py +16 -14
pages/1_paper_search.py
CHANGED
|
@@ -13,7 +13,6 @@ import numpy as np
|
|
| 13 |
|
| 14 |
# openai.organization = st.secrets.openai.org
|
| 15 |
# openai.api_key = st.secrets.openai.api_key
|
| 16 |
-
st.write(st.secrets['openai'])
|
| 17 |
openai.organization = st.secrets["org"]
|
| 18 |
openai.api_key = st.secrets["api_key"]
|
| 19 |
os.environ["OPENAI_API_KEY"] = openai.api_key
|
|
|
|
| 13 |
|
| 14 |
# openai.organization = st.secrets.openai.org
|
| 15 |
# openai.api_key = st.secrets.openai.api_key
|
|
|
|
| 16 |
openai.organization = st.secrets["org"]
|
| 17 |
openai.api_key = st.secrets["api_key"]
|
| 18 |
os.environ["OPENAI_API_KEY"] = openai.api_key
|
pages/3_qa_sources.py
CHANGED
|
@@ -18,8 +18,10 @@ from langchain.document_loaders import TextLoader
|
|
| 18 |
from langchain.indexes import VectorstoreIndexCreator
|
| 19 |
API_ENDPOINT = "https://api.openai.com/v1/chat/completions"
|
| 20 |
|
| 21 |
-
openai.organization = st.secrets.openai.org
|
| 22 |
-
openai.api_key = st.secrets.openai.api_key
|
|
|
|
|
|
|
| 23 |
os.environ["OPENAI_API_KEY"] = openai.api_key
|
| 24 |
|
| 25 |
@st.cache_data
|
|
@@ -190,20 +192,20 @@ def generate_chat_completion(messages, model="gpt-4", temperature=1, max_tokens=
|
|
| 190 |
return response.json()["choices"][0]["message"]["content"]
|
| 191 |
else:
|
| 192 |
raise Exception(f"Error {response.status_code}: {response.text}")
|
| 193 |
-
|
| 194 |
-
|
| 195 |
model_data = [arxiv_ada_embeddings, embeddings, all_titles, all_text, all_authors]
|
| 196 |
|
| 197 |
def run_query(query, return_n = 3, show_pure_answer = False, show_all_sources = True):
|
| 198 |
-
|
| 199 |
show_authors = True
|
| 200 |
show_summary = True
|
| 201 |
-
sims, absts, fhdrs, simids = list_similar_papers_v2(model_data,
|
| 202 |
-
doc_id = query,
|
| 203 |
-
input_type='keywords',
|
| 204 |
-
show_authors = show_authors, show_summary = show_summary,
|
| 205 |
return_n = return_n)
|
| 206 |
-
|
| 207 |
temp_abst = ''
|
| 208 |
loaders = []
|
| 209 |
for i in range(len(absts)):
|
|
@@ -239,7 +241,7 @@ def run_query(query, return_n = 3, show_pure_answer = False, show_all_sources =
|
|
| 239 |
textstr = ''
|
| 240 |
ng = len(output['sources'].split())
|
| 241 |
abs_indices = []
|
| 242 |
-
|
| 243 |
for i in range(ng):
|
| 244 |
if i == (ng-1):
|
| 245 |
tempid = output['sources'].split()[i].split('_')[1][0:-4]
|
|
@@ -271,13 +273,13 @@ def run_query(query, return_n = 3, show_pure_answer = False, show_all_sources =
|
|
| 271 |
textstr = textstr + ' '
|
| 272 |
textstr = textstr + ' \n'
|
| 273 |
st.markdown(textstr)
|
| 274 |
-
|
| 275 |
fig = plt.figure(figsize=(9,9))
|
| 276 |
plt.scatter(e2d[0:,0], e2d[0:,1],s=2)
|
| 277 |
plt.scatter(e2d[simids,0], e2d[simids,1],s=30)
|
| 278 |
plt.scatter(e2d[abs_indices,0], e2d[abs_indices,1],s=100,color='k',marker='d')
|
| 279 |
st.pyplot(fig)
|
| 280 |
-
|
| 281 |
if show_all_sources == True:
|
| 282 |
st.markdown('\n #### Other interesting papers:')
|
| 283 |
st.markdown(sims)
|
|
@@ -289,4 +291,4 @@ st.markdown('Concise answers for questions using arxiv abstracts + GPT-4. Please
|
|
| 289 |
query = st.text_input('Your question here:', value="What sersic index does a disk galaxy have?")
|
| 290 |
return_n = st.slider('How many papers should I show?', 1, 20, 10)
|
| 291 |
|
| 292 |
-
sims = run_query(query, return_n = return_n)
|
|
|
|
| 18 |
from langchain.indexes import VectorstoreIndexCreator
|
| 19 |
API_ENDPOINT = "https://api.openai.com/v1/chat/completions"
|
| 20 |
|
| 21 |
+
# openai.organization = st.secrets.openai.org
|
| 22 |
+
# openai.api_key = st.secrets.openai.api_key
|
| 23 |
+
openai.organization = st.secrets["org"]
|
| 24 |
+
openai.api_key = st.secrets["api_key"]
|
| 25 |
os.environ["OPENAI_API_KEY"] = openai.api_key
|
| 26 |
|
| 27 |
@st.cache_data
|
|
|
|
| 192 |
return response.json()["choices"][0]["message"]["content"]
|
| 193 |
else:
|
| 194 |
raise Exception(f"Error {response.status_code}: {response.text}")
|
| 195 |
+
|
| 196 |
+
|
| 197 |
model_data = [arxiv_ada_embeddings, embeddings, all_titles, all_text, all_authors]
|
| 198 |
|
| 199 |
def run_query(query, return_n = 3, show_pure_answer = False, show_all_sources = True):
|
| 200 |
+
|
| 201 |
show_authors = True
|
| 202 |
show_summary = True
|
| 203 |
+
sims, absts, fhdrs, simids = list_similar_papers_v2(model_data,
|
| 204 |
+
doc_id = query,
|
| 205 |
+
input_type='keywords',
|
| 206 |
+
show_authors = show_authors, show_summary = show_summary,
|
| 207 |
return_n = return_n)
|
| 208 |
+
|
| 209 |
temp_abst = ''
|
| 210 |
loaders = []
|
| 211 |
for i in range(len(absts)):
|
|
|
|
| 241 |
textstr = ''
|
| 242 |
ng = len(output['sources'].split())
|
| 243 |
abs_indices = []
|
| 244 |
+
|
| 245 |
for i in range(ng):
|
| 246 |
if i == (ng-1):
|
| 247 |
tempid = output['sources'].split()[i].split('_')[1][0:-4]
|
|
|
|
| 273 |
textstr = textstr + ' '
|
| 274 |
textstr = textstr + ' \n'
|
| 275 |
st.markdown(textstr)
|
| 276 |
+
|
| 277 |
fig = plt.figure(figsize=(9,9))
|
| 278 |
plt.scatter(e2d[0:,0], e2d[0:,1],s=2)
|
| 279 |
plt.scatter(e2d[simids,0], e2d[simids,1],s=30)
|
| 280 |
plt.scatter(e2d[abs_indices,0], e2d[abs_indices,1],s=100,color='k',marker='d')
|
| 281 |
st.pyplot(fig)
|
| 282 |
+
|
| 283 |
if show_all_sources == True:
|
| 284 |
st.markdown('\n #### Other interesting papers:')
|
| 285 |
st.markdown(sims)
|
|
|
|
| 291 |
query = st.text_input('Your question here:', value="What sersic index does a disk galaxy have?")
|
| 292 |
return_n = st.slider('How many papers should I show?', 1, 20, 10)
|
| 293 |
|
| 294 |
+
sims = run_query(query, return_n = return_n)
|