|
| 1 | +import streamlit as st |
| 2 | +from scholarly import scholarly |
| 3 | +import pandas as pd |
| 4 | +import google.generativeai as genai |
| 5 | +import os |
| 6 | + |
| 7 | +# Configure Google Generative AI |
| 8 | +genai.configure(api_key=os.getenv("GOOGLE_API_KEY")) |
| 9 | + |
| 10 | +# Streamlit App |
| 11 | +st.title("🤖 Research Profile Summarizer") |
| 12 | + |
| 13 | +# Input for author name |
| 14 | +author_name = st.text_input("Enter the author's name:", "Steven A Cholewiak") |
| 15 | + |
| 16 | +if st.button("Generate Summary"): |
| 17 | + # Retrieve the author's data |
| 18 | + search_query = scholarly.search_author(author_name) |
| 19 | + first_author_result = next(search_query) |
| 20 | + author = scholarly.fill(first_author_result) |
| 21 | + |
| 22 | + # Initialize a string to store all textual data |
| 23 | + summary_text = "" |
| 24 | + |
| 25 | + # Display author's name and affiliation |
| 26 | + author_info = [ |
| 27 | + f"**Name:** {author['name']}", |
| 28 | + f"**Affiliation:** {author.get('affiliation', 'N/A')}" |
| 29 | + ] |
| 30 | + |
| 31 | + st.subheader("Author Information") |
| 32 | + for info in author_info: |
| 33 | + st.write(info) # Display each piece of information as a separate line |
| 34 | + summary_text += info + "\n" |
| 35 | + |
| 36 | + |
| 37 | + # Display research interests as a list |
| 38 | + st.subheader("Research Interests") |
| 39 | + interests = author.get('interests', []) |
| 40 | + if interests: |
| 41 | + interests_list = "- " + "\n- ".join(interests) # Display interests as a bullet list |
| 42 | + st.write(interests_list) |
| 43 | + summary_text += f"**Research Interests:**\n{interests_list}\n" |
| 44 | + else: |
| 45 | + st.write('N/A') |
| 46 | + summary_text += "**Research Interests:** N/A\n" |
| 47 | + |
| 48 | + # Citations overview |
| 49 | + st.subheader("Citations Overview") |
| 50 | + citations = { |
| 51 | + "Total Citations": author.get('citedby', 'N/A'), |
| 52 | + "Citations (Last 5 Years)": author.get('citedby5y', 'N/A') |
| 53 | + } |
| 54 | + for citation_name, citation_value in citations.items(): |
| 55 | + st.write(f"**{citation_name}:** {citation_value}") |
| 56 | + summary_text += f"**{citation_name}:** {citation_value}\n" |
| 57 | + |
| 58 | + # Citations per year |
| 59 | + citations_per_year = author.get('cites_per_year', {}) |
| 60 | + if citations_per_year: |
| 61 | + citations_df = pd.DataFrame(list(citations_per_year.items()), columns=['Year', 'Citations']) |
| 62 | + st.subheader("Citations Per Year") |
| 63 | + st.line_chart(citations_df.set_index('Year')) |
| 64 | + summary_text += "Citations data is available.\n" |
| 65 | + else: |
| 66 | + st.write("No citation data available for the past years.") |
| 67 | + summary_text += "No citation data available for the past years.\n" |
| 68 | + |
| 69 | + # Indexes |
| 70 | + st.subheader("Indexes") |
| 71 | + indexes = { |
| 72 | + "H-Index": author.get('hindex', 'N/A'), |
| 73 | + "H-Index (Last 5 Years)": author.get('hindex5y', 'N/A'), |
| 74 | + "i10-Index": author.get('i10index', 'N/A'), |
| 75 | + "i10-Index (Last 5 Years)": author.get('i10index5y', 'N/A') |
| 76 | + } |
| 77 | + |
| 78 | + # Displaying indexes in a more structured format |
| 79 | + for index_name, index_value in indexes.items(): |
| 80 | + st.write(f"**{index_name}:** {index_value}") |
| 81 | + summary_text += f"**{index_name}:** {index_value}\n" |
| 82 | + |
| 83 | + # Display top publications |
| 84 | + st.subheader("Top Publications") |
| 85 | + top_publications = sorted(author['publications'], key=lambda x: x.get('num_citations', 0), reverse=True)[:5] |
| 86 | + top_publications_text = "" |
| 87 | + for pub in top_publications: |
| 88 | + pub_filled = scholarly.fill(pub) |
| 89 | + publication_info = f"- **{pub_filled['bib']['title']}** (Citations: {pub_filled.get('num_citations', 0)})" |
| 90 | + st.write(publication_info) |
| 91 | + top_publications_text += publication_info + "\n" |
| 92 | + |
| 93 | + summary_text += f"**Top Publications:**\n{top_publications_text}\n" |
| 94 | + |
| 95 | + # Generate summary using Google Generative AI |
| 96 | + model = genai.GenerativeModel("gemini-pro") |
| 97 | + chat = model.start_chat(history=[]) |
| 98 | + |
| 99 | + # Function to generate summary using Gemini Pro model |
| 100 | + def generate_summary(data): |
| 101 | + summary_prompt = f"Write a concise 200-word summary based on the following information:\n{data}\nInclude key details like research interests, citations, H-index, co-authors, and notable publications." |
| 102 | + response = chat.send_message(summary_prompt) |
| 103 | + summary = "".join([chunk.text for chunk in response]) |
| 104 | + return summary |
| 105 | + |
| 106 | + # Generate and display the summary |
| 107 | + generated_summary = generate_summary(summary_text) |
| 108 | + st.subheader("Profile Summary") |
| 109 | + st.write(generated_summary) |
0 commit comments