Papajams commited on
Commit
46722e7
·
1 Parent(s): ffbdc79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -29
app.py CHANGED
@@ -1,35 +1,40 @@
1
  import streamlit as st
2
  import requests
3
- from urllib.parse import quote
4
 
5
- def search_papers(user_input, max_results=3):
6
- url = "https://api.openaire.eu/search/publications?title=" + quote(user_input)
7
- try:
8
- with requests.Session() as session:
9
- response = session.get(url)
10
- if response.status_code == 200:
11
- data = response.json()
12
- if 'response' in data.keys() and 'results' in data['response']:
13
- search_results = data["response"]["results"][:max_results]
14
- return search_results
15
- except requests.exceptions.RequestException as e:
16
- st.error(f"An error occurred: {str(e)}")
17
- return None
 
18
 
19
- st.title('The Substantiator')
 
 
 
 
 
 
 
 
 
20
 
21
- user_input = st.text_input('Input your claim')
 
22
 
23
- if st.button('Substantiate'):
24
- search_results = search_papers(user_input)
25
- if search_results is not None and len(search_results) > 0:
26
- for result in search_results:
27
- if 'title' in result.keys() and 'link' in result.keys() and 'url' in result['link']:
28
- st.markdown(f"[{result['title']}]({result['link']['url']})", unsafe_allow_html=True)
29
- if 'creator' in result.keys():
30
- st.markdown(f"**Author(s):** {result['creator']}")
31
- if 'dateofacceptance' in result.keys():
32
- st.markdown(f"**Date of Acceptance:** {result['dateofacceptance']}")
33
- st.markdown("---")
34
- else:
35
- st.write("No results found.")
 
1
  import streamlit as st
2
  import requests
3
+ from bs4 import BeautifulSoup
4
 
5
+ def search_arxiv(search_query: str, start: int = 0):
6
+ base_url = 'http://export.arxiv.org/api/query?'
7
+ query = f'search_query={search_query}&start={start}&max_results=10'
8
+ response = requests.get(base_url + query)
9
+ feed = BeautifulSoup(response.content, 'html.parser')
10
+ entries = feed.find_all('entry')
11
+ articles = []
12
+ for entry in entries:
13
+ article = {}
14
+ article['title'] = entry.title.text
15
+ article['authors'] = [author.find('name').text for author in entry.find_all('author')]
16
+ article['abstract'] = entry.summary.text
17
+ articles.append(article)
18
+ return articles
19
 
20
+ def get_paper_info(paper_id: str):
21
+ base_url = 'https://api.semanticscholar.org/v1/paper/'
22
+ response = requests.get(base_url + paper_id)
23
+ paper = response.json()
24
+ paper_info = {}
25
+ paper_info['title'] = paper['title']
26
+ paper_info['authors'] = [author['name'] for author in paper['authors']]
27
+ paper_info['abstract'] = paper['abstract']
28
+ paper_info['fieldsOfStudy'] = paper['fieldsOfStudy']
29
+ return paper_info
30
 
31
+ st.title('Scientific Data Substantiator')
32
+ search_query = st.text_input("Enter your search term")
33
 
34
+ if search_query:
35
+ articles = search_arxiv(search_query)
36
+ for article in articles:
37
+ st.write("Title: ", article['title'])
38
+ st.write("Authors: ", ", ".join(article['authors']))
39
+ st.write("Abstract: ", article['abstract'])
40
+ st.write("-----")