Spaces:
Sleeping
Sleeping
Akshayram1
commited on
Commit
•
329e507
1
Parent(s):
489301b
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ import os
|
|
7 |
load_dotenv()
|
8 |
|
9 |
# Configure Google Generative AI with API key
|
10 |
-
api_key = os.getenv("
|
11 |
genai.configure(api_key=api_key)
|
12 |
|
13 |
# Initialize the session state to store chat history
|
@@ -71,24 +71,47 @@ def text_summary(text, isNew=False):
|
|
71 |
# Layout for chatbot UI
|
72 |
st.title("Financial Summary Chatbot")
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
# Chat history container (This is where the conversation will appear)
|
75 |
chat_container = st.container()
|
76 |
|
77 |
-
#
|
78 |
-
input_container = st.container()
|
79 |
-
|
80 |
-
# Function to display the chat history
|
81 |
def display_chat():
|
82 |
with chat_container:
|
|
|
83 |
# Loop through session messages and display them
|
84 |
for message in st.session_state['messages']:
|
85 |
if message['role'] == 'user':
|
86 |
st.write(f"**You:** {message['content']}")
|
87 |
else:
|
88 |
st.write(f"**Bot:** {message['content']}")
|
|
|
|
|
|
|
|
|
89 |
|
90 |
# Fixed input area at the bottom using the input container
|
91 |
with input_container:
|
|
|
92 |
is_new_session = st.checkbox("Start new session", value=False)
|
93 |
user_input = st.text_area("Type your message here:", height=100)
|
94 |
send_button = st.button("Send")
|
@@ -107,5 +130,7 @@ with input_container:
|
|
107 |
# Clear the input text area
|
108 |
user_input = ""
|
109 |
|
|
|
|
|
110 |
# Display the chat history
|
111 |
display_chat()
|
|
|
7 |
load_dotenv()
|
8 |
|
9 |
# Configure Google Generative AI with API key
|
10 |
+
api_key = os.getenv("GENERATIVEAI_API_KEY")
|
11 |
genai.configure(api_key=api_key)
|
12 |
|
13 |
# Initialize the session state to store chat history
|
|
|
71 |
# Layout for chatbot UI
|
72 |
st.title("Financial Summary Chatbot")
|
73 |
|
74 |
+
# Adding custom CSS for scrollable chat output
|
75 |
+
st.markdown("""
|
76 |
+
<style>
|
77 |
+
.chat-output {
|
78 |
+
max-height: 400px;
|
79 |
+
overflow-y: scroll;
|
80 |
+
padding: 10px;
|
81 |
+
border: 1px solid #ccc;
|
82 |
+
background-color: #f5f5f5;
|
83 |
+
}
|
84 |
+
.input-container {
|
85 |
+
position: fixed;
|
86 |
+
bottom: 0;
|
87 |
+
width: 100%;
|
88 |
+
background-color: #fff;
|
89 |
+
padding: 10px 0;
|
90 |
+
}
|
91 |
+
</style>
|
92 |
+
""", unsafe_allow_html=True)
|
93 |
+
|
94 |
# Chat history container (This is where the conversation will appear)
|
95 |
chat_container = st.container()
|
96 |
|
97 |
+
# Function to display the chat history in a scrollable container
|
|
|
|
|
|
|
98 |
def display_chat():
|
99 |
with chat_container:
|
100 |
+
st.markdown('<div class="chat-output">', unsafe_allow_html=True)
|
101 |
# Loop through session messages and display them
|
102 |
for message in st.session_state['messages']:
|
103 |
if message['role'] == 'user':
|
104 |
st.write(f"**You:** {message['content']}")
|
105 |
else:
|
106 |
st.write(f"**Bot:** {message['content']}")
|
107 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
108 |
+
|
109 |
+
# Input container (This will stay at the bottom)
|
110 |
+
input_container = st.container()
|
111 |
|
112 |
# Fixed input area at the bottom using the input container
|
113 |
with input_container:
|
114 |
+
st.markdown('<div class="input-container">', unsafe_allow_html=True)
|
115 |
is_new_session = st.checkbox("Start new session", value=False)
|
116 |
user_input = st.text_area("Type your message here:", height=100)
|
117 |
send_button = st.button("Send")
|
|
|
130 |
# Clear the input text area
|
131 |
user_input = ""
|
132 |
|
133 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
134 |
+
|
135 |
# Display the chat history
|
136 |
display_chat()
|