-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
84 lines (60 loc) · 2.26 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import pickle
import streamlit as st
from rag import rag
from summaries import get_summaries
from topic_modeling import topic_modeling
def main():
# --- Streamlit page configuration ---
# Set the title for the Streamlit app
st.title("Trending Research Papers - Summary and AI Chat")
st.caption("from https://paperswithcode.com/")
st.write(
"""
Trending research titles are scraped from paperswithcode.com and summaries are pulled from Arxiv. An AI chatbot assists with questions and answers based on these papers.
"""
)
st.write("Jump to Section:")
st.markdown("[Summaries](#summaries)")
st.markdown("[AI Chat](#aichat)")
st.divider()
st.header("Summaries", anchor="summaries", divider="gray")
# Keywords from topic modeling
filename = "data/topic_data.pkl"
with open(filename, "rb") as file:
topics_dict = pickle.load(file)
# n_topic_list = topics_dict['n_topic_list']
topic_lists = topics_dict["topic_lists"]
# n_topic_list = 2
st.write(f"Keywords:")
# Just put both topic lists together for now as keywords.
keyword_list = []
for list in topic_lists:
concatenated_items = ", ".join(list)
keyword_list.append(concatenated_items)
concatenated_keyword_list = ", ".join(keyword_list)
st.write(concatenated_keyword_list)
st.divider()
summaries = get_summaries()
for summary in summaries:
st.write(summary)
# For RAG-CHAT
st.header("AI Chat", anchor="aichat", divider="gray")
with st.form(key="my_form", clear_on_submit=False):
user_input = st.text_input(
"Prompt:",
placeholder="Ask a question about this trending research",
key="input",
)
submit_button = st.form_submit_button(label="Ask")
# If asking for OpenAI API Key
# with st.sidebar:
# openai_api_key = st.text_input("OpenAI API Key", key="chatbot_api_key", type="password")
# "[Get an OpenAI API key](https://platform.openai.com/account/api-keys)"
# if not openai_api_key:
# st.info("Please add your OpenAI API key to continue.")
# st.stop()
if user_input:
result = rag(user_input)
st.write(result)
if __name__ == "__main__":
main()