Papajams commited on
Commit
ecde3db
1 Parent(s): 5cc8b6e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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?query=" + 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.")