arad1367 commited on
Commit
18e52ab
·
verified ·
1 Parent(s): 4b96ebd

Upload 4 files

Browse files
Files changed (4) hide show
  1. .streamlit/config.toml +5 -0
  2. app.py +55 -0
  3. logo.jpg +0 -0
  4. requirements.txt +0 -0
.streamlit/config.toml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ [theme]
2
+ primaryColor="#50d811"
3
+ backgroundColor="#0b0c0a"
4
+ secondaryBackgroundColor="#115603"
5
+ textColor="#f5f5f9"
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain_openai import ChatOpenAI
3
+ from langchain.schema import AIMessage, HumanMessage, SystemMessage
4
+
5
+ # StreamLit UI
6
+ st.set_page_config(page_title="EcoCoinBot", page_icon=":robot:")
7
+
8
+ # Define the function to add an image at the top center
9
+ def add_image(image, width):
10
+ st.image(image, width=width)
11
+
12
+ # Add the image at the top center with adjusted width
13
+ add_image("logo.jpg", width=200) # Adjust the width as needed
14
+
15
+ st.header("Hey, I'm EcoCoinBot. I'm a sustainable cryptocurrency advisor. I'm your friend")
16
+
17
+ # Input OpenAI API key
18
+ openai_api_key = st.text_input("Enter your OpenAI API Key:", type="password")
19
+
20
+ # Create sessionMessages if not already exists
21
+ if "sessionMessages" not in st.session_state:
22
+ st.session_state.sessionMessages = [
23
+ SystemMessage(content="Your name is EcoCoinBot. You are a sustainable cryptocurrency investment advisor. Please only answer questions related to sustainable cryptocurrency. If a question is not related to this field, simply respond with, 'This question is not relevant to sustainable cryptocurrency. Please ask another question.'")
24
+ ]
25
+
26
+ # Function to load answer
27
+ def load_answer(question):
28
+ st.session_state.sessionMessages.append(HumanMessage(content=question))
29
+ try:
30
+ assistant_answer = chat.invoke(st.session_state.sessionMessages)
31
+ st.session_state.sessionMessages.append(AIMessage(content=assistant_answer.content))
32
+ return assistant_answer.content
33
+ except Exception as e:
34
+ if "Incorrect API key" in str(e):
35
+ return "The provided OpenAI API Key is incorrect. Please try again."
36
+ else:
37
+ return "An error occurred. Please try again later."
38
+
39
+ # Function to get user input
40
+ def get_text():
41
+ input_text = st.text_input("User: ")
42
+ return input_text
43
+
44
+ # Proceed if OpenAI API key is provided
45
+ if openai_api_key:
46
+ chat = ChatOpenAI(temperature=0, openai_api_key=openai_api_key)
47
+ user_input = get_text()
48
+ submit = st.button('Generate')
49
+
50
+ if submit:
51
+ response = load_answer(user_input)
52
+ st.subheader("Answer:")
53
+ st.write(response)
54
+ else:
55
+ st.warning("Please enter your OpenAI API Key to use this app.")
logo.jpg ADDED
requirements.txt ADDED
Binary file (244 Bytes). View file