i want to build an application which basically takes keywords and journals as inputs and outputs the research papers that it found on the journals. The application should also be able to save those to an excel file [excel file containing authors, title of paper, journal, conference, date, and link to the paper].
To upload files, please first save the app
import streamlit as st
import pandas as pd
from scholarly import scholarly
import datetime
st.title("Research Paper Finder")
# Input fields
keywords = st.text_input("Enter keywords (separate multiple keywords with commas)")
journals = st.text_input("Enter journal names (separate multiple journals with commas)")
if st.button("Search Papers"):
if keywords and journals:
st.info("Searching for papers... This may take a few moments.")
# Process inputs
keyword_list = [k.strip() for k in keywords.split(",")]
journal_list = [j.strip() for j in journals.split(",")]
# Initialize results list
results = []
# Search for each keyword
for keyword in keyword_list:
search_query = scholarly.search_pubs(keyword)
# Get first 10 results for each keyword
try:
for i in range(10):
publication = next(search_query)
# Check if the publication is from one of the specified journals
pub_journal = publication.get('journal', '').lower()
if any(journal.lower() in pub_journal for journal in journal_list):
# Extract relevant information
result = {
'Title': publication.get('title', 'N/A'),
'Authors': ', '.join(publication.get('author', [])),
'Journal': publication.get('journal', 'N/A'),
'Year': publication.get('year', 'N/A'),
'Conference': publication.get('conference', 'N/A'),
'Link': publication.get('url', 'N/A')
}
results.append(result)
except StopIteration:
continue
if results:
# Create DataFrame
df = pd.DataFrame(results)
# Display results in the app
st.subheader("Search Results")
st.dataframe(df)
# Create Excel file
excel_file = df.to_excel(index=False)
# Generate timestamp for filename
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"research_papers_{timestamp}.xlsx"
# Save to Excel and provide download button
df.to_excel(filename, index=False)
with open(filename, 'rb') as f:
st.download_button(
label="Download Results as Excel",
data=f,
file_name=filename,
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)
else:
st.warning("No matching papers found in the specified journals.")
else:
st.error("Please enter both keywords and journal names.")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?