Prathamesh1420 commited on
Commit
cdf7e24
·
verified ·
1 Parent(s): fc77ca9

Update app.py

Browse files

api key send to environment

Files changed (1) hide show
  1. app.py +56 -53
app.py CHANGED
@@ -1,61 +1,64 @@
1
  import streamlit as st
2
  import taskingai
 
3
  import pprint as pp
4
 
5
- # Initialize the Tasking AI with your API key
6
- api_key = "tav93qvwboJoczXrVlJXA3z3XksD4kTG"
7
- taskingai.init(api_key)
8
-
9
- # Set up Streamlit page configuration
10
- st.set_page_config(
11
- page_title="Research Paper Finder",
12
- page_icon="🔍",
13
- menu_items={
14
- 'About': "# Made by Prathamesh Khade"
15
- }
16
- )
17
-
18
- # Title of the app
19
- st.title("Research Paper Finder")
20
- st.markdown("## Find the latest research papers.")
21
-
22
-
23
-
24
- # User input with text_area for multi-line input
25
- user_input = st.text_area(
26
- "Enter your query:",
27
- value="Get me a list of RAG papers from 2024. Include the source, title, author, publication date, a brief summary, githublink and a link to each paper.",
28
- height=150
29
- )
30
-
31
- # Initialize the arxiv_qa_assistant
32
- assistants = taskingai.assistant.list_assistants()
33
- arxiv_qa_assistant = next((assistant for assistant in assistants if assistant.name == "arxivagent"), None)
34
-
35
- if arxiv_qa_assistant:
36
- new_chat = taskingai.assistant.create_chat(assistant_id=arxiv_qa_assistant.assistant_id)
37
-
38
- if st.button("Find Papers"):
39
- with st.spinner("Finding papers..."):
40
- user_message = taskingai.assistant.create_message(
41
- assistant_id=arxiv_qa_assistant.assistant_id,
42
- chat_id=new_chat.chat_id,
43
- text=user_input
44
- )
45
-
46
- assistant_message = taskingai.assistant.generate_message(
47
- assistant_id=arxiv_qa_assistant.assistant_id,
48
- chat_id=new_chat.chat_id
49
- )
50
-
51
- # Extract the text content from the assistant_message
52
- response_text = assistant_message.content.text
53
-
54
- # Display the result
55
- st.success("Papers found!")
56
- st.markdown(response_text)
57
  else:
58
- st.error("Could not find arxiv_qa_assistant. Please check the assistant name.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  # Run Streamlit app
61
  if __name__ == '__main__':
 
1
  import streamlit as st
2
  import taskingai
3
+ import os
4
  import pprint as pp
5
 
6
+ # Read the API key from an environment variable
7
+ api_key = os.getenv("TASKINGAI_API_KEY")
8
+ if not api_key:
9
+ st.error("API key not found. Please set the TASKINGAI_API_KEY environment variable.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  else:
11
+ # Initialize the Tasking AI with your API key
12
+ taskingai.init(api_key)
13
+
14
+ # Set up Streamlit page configuration
15
+ st.set_page_config(
16
+ page_title="Research Paper Finder",
17
+ page_icon="🔍",
18
+ menu_items={
19
+ 'About': "# Made by Prathamesh Khade"
20
+ }
21
+ )
22
+
23
+ # Title of the app
24
+ st.title("Research Paper Finder")
25
+ st.markdown("## Find the latest research papers.")
26
+
27
+ # User input with text_area for multi-line input
28
+ user_input = st.text_area(
29
+ "Enter your query:",
30
+ value="Get me a list of RAG papers from 2024. Include the source, title, author, publication date, a brief summary, githublink and a link to each paper.",
31
+ height=150
32
+ )
33
+
34
+ # Initialize the arxiv_qa_assistant
35
+ assistants = taskingai.assistant.list_assistants()
36
+ arxiv_qa_assistant = next((assistant for assistant in assistants if assistant.name == "arxivagent"), None)
37
+
38
+ if arxiv_qa_assistant:
39
+ new_chat = taskingai.assistant.create_chat(assistant_id=arxiv_qa_assistant.assistant_id)
40
+
41
+ if st.button("Find Papers"):
42
+ with st.spinner("Finding papers..."):
43
+ user_message = taskingai.assistant.create_message(
44
+ assistant_id=arxiv_qa_assistant.assistant_id,
45
+ chat_id=new_chat.chat_id,
46
+ text=user_input
47
+ )
48
+
49
+ assistant_message = taskingai.assistant.generate_message(
50
+ assistant_id=arxiv_qa_assistant.assistant_id,
51
+ chat_id=new_chat.chat_id
52
+ )
53
+
54
+ # Extract the text content from the assistant_message
55
+ response_text = assistant_message.content.text
56
+
57
+ # Display the result
58
+ st.success("Papers found!")
59
+ st.markdown(response_text)
60
+ else:
61
+ st.error("Could not find arxiv_qa_assistant. Please check the assistant name.")
62
 
63
  # Run Streamlit app
64
  if __name__ == '__main__':