Akshayram1 commited on
Commit
75b3cda
·
verified ·
1 Parent(s): a1e3c3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -21
app.py CHANGED
@@ -1,5 +1,3 @@
1
- # app.py
2
-
3
  import streamlit as st
4
  import google.generativeai as genai
5
  from dotenv import load_dotenv
@@ -12,13 +10,9 @@ load_dotenv()
12
  api_key = os.getenv("GENERATIVEAI_API_KEY")
13
  genai.configure(api_key=api_key)
14
 
15
- # Global variable to maintain chat session and history
16
  chat = None
17
- if 'chat_history' not in st.session_state:
18
- st.session_state.chat_history = [] # Initialize chat history
19
- if 'input' not in st.session_state:
20
- st.session_state.input = "" # Initialize input state
21
-
22
  # Generation configuration and safety settings
23
  generation_config = {
24
  "temperature": 0.9,
@@ -133,23 +127,26 @@ def text_summary(text, isNew=False):
133
  st.title("Financial Summary Chatbot")
134
  st.write("Welcome to the Financial Summary Chatbot! Enter your text below to get a financial summary.")
135
 
136
- # Display chat history at the top
137
- if st.session_state.chat_history:
138
- for entry in st.session_state.chat_history:
139
- st.markdown(entry, unsafe_allow_html=True)
140
-
141
- # Input area for user text at the bottom
142
- user_input = st.text_area("Enter your text here:", value=st.session_state.input)
143
 
144
  # Button to submit the text
145
  if st.button("Get Summary"):
146
  if user_input.strip():
147
  summary = text_summary(user_input, isNew=True) # Start a new session each time
148
- # Add user input and summary to chat history
149
- st.session_state.chat_history.append(f"<strong>You:</strong><br/>{user_input}<br/><br/>")
150
- st.session_state.chat_history.append(f"<strong>Bot:</strong><br/>{summary}<br/><br/>")
151
- # Clear the text area by resetting the input session state
152
- st.session_state.input = "" # Reset input state to empty
153
- st.experimental_rerun() # Rerun the script to refresh the input field
154
  else:
155
  st.warning("Please enter some text to summarize.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  import google.generativeai as genai
3
  from dotenv import load_dotenv
 
10
  api_key = os.getenv("GENERATIVEAI_API_KEY")
11
  genai.configure(api_key=api_key)
12
 
13
+ # Global variable to maintain chat session
14
  chat = None
15
+
 
 
 
 
16
  # Generation configuration and safety settings
17
  generation_config = {
18
  "temperature": 0.9,
 
127
  st.title("Financial Summary Chatbot")
128
  st.write("Welcome to the Financial Summary Chatbot! Enter your text below to get a financial summary.")
129
 
130
+ # Input area for user text
131
+ user_input = st.text_area("Enter your text here:", "")
 
 
 
 
 
132
 
133
  # Button to submit the text
134
  if st.button("Get Summary"):
135
  if user_input.strip():
136
  summary = text_summary(user_input, isNew=True) # Start a new session each time
137
+ st.write("### Summary:")
138
+ st.markdown(summary, unsafe_allow_html=True)
 
 
 
 
139
  else:
140
  st.warning("Please enter some text to summarize.")
141
+
142
+ # Chatbot UI
143
+ st.write("### Chatbot")
144
+ st.write("Type a message to get a response from the chatbot.")
145
+ chat_input = st.text_area("Type a message:", "")
146
+ if st.button("Send"):
147
+ if chat_input.strip():
148
+ response = text_summary(chat_input)
149
+ st.write("### Response:")
150
+ st.markdown(response, unsafe_allow_html=True)
151
+ else:
152
+ st.warning("Please enter a message to send.")