substantiator / app.py
Papajams's picture
Create app.py
ecde3db
raw
history blame
1.5 kB
import streamlit as st
import requests
from urllib.parse import quote
def search_papers(user_input, max_results=3):
url = "https://api.openaire.eu/search/publications?query=" + quote(user_input)
try:
with requests.Session() as session:
response = session.get(url)
if response.status_code == 200:
data = response.json()
if 'response' in data.keys() and 'results' in data['response']:
search_results = data["response"]["results"][:max_results]
return search_results
except requests.exceptions.RequestException as e:
st.error(f"An error occurred: {str(e)}")
return None
st.title('The Substantiator')
user_input = st.text_input('Input your claim')
if st.button('Substantiate'):
search_results = search_papers(user_input)
if search_results is not None and len(search_results) > 0:
for result in search_results:
if 'title' in result.keys() and 'link' in result.keys() and 'url' in result['link']:
st.markdown(f"[{result['title']}]({result['link']['url']})", unsafe_allow_html=True)
if 'creator' in result.keys():
st.markdown(f"**Author(s):** {result['creator']}")
if 'dateofacceptance' in result.keys():
st.markdown(f"**Date of Acceptance:** {result['dateofacceptance']}")
st.markdown("---")
else:
st.write("No results found.")