Sumayyea commited on
Commit
86e92a3
·
verified ·
1 Parent(s): 0e450f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -22
app.py CHANGED
@@ -7,8 +7,8 @@ GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
7
  genai.configure(api_key=GOOGLE_API_KEY)
8
 
9
  # Initialize the Generative Model
10
- # model = genai.GenerativeModel('gemini-pro')
11
  model = genai.GenerativeModel('gemini-2.5-flash')
 
12
  # Function to get response from the model
13
  def get_chatbot_response(user_input):
14
  response = model.generate_content(user_input)
@@ -16,14 +16,22 @@ def get_chatbot_response(user_input):
16
 
17
  # Streamlit interface
18
  st.set_page_config(page_title="Simple ChatBot", layout="centered")
19
-
20
  st.title("✨ Simple ChatBot ✨")
21
  st.write("Powered by Google Generative AI")
22
 
23
  if "history" not in st.session_state:
24
  st.session_state["history"] = []
25
 
26
- # Display chat history
 
 
 
 
 
 
 
 
 
27
  for user_message, bot_message in st.session_state.history:
28
  st.markdown(f"""
29
  <div style="
@@ -38,7 +46,7 @@ for user_message, bot_message in st.session_state.history:
38
  <p style="margin: 0; font-size: 16px; line-height: 1.5;"><b>You:</b> {user_message} 😊</p>
39
  </div>
40
  """, unsafe_allow_html=True)
41
-
42
  st.markdown(f"""
43
  <div style="
44
  background-color: #e1ffc7;
@@ -51,21 +59,4 @@ for user_message, bot_message in st.session_state.history:
51
  ">
52
  <p style="margin: 0; font-size: 16px; line-height: 1.5;"><b>Bot:</b> {bot_message} 🤖</p>
53
  </div>
54
- """, unsafe_allow_html=True)
55
-
56
- # user_input = input("Enter your Prompt = ")
57
- # output = get_chatbot_response(user_input)
58
-
59
- # print(output)
60
-
61
- with st.form(key="chat_form", clear_on_submit=True):
62
- user_input = st.text_input("", max_chars=2000)
63
- submit_button = st.form_submit_button("Send")
64
-
65
- if submit_button:
66
- if user_input:
67
- response = get_chatbot_response(user_input)
68
- st.session_state.history.append((user_input, response))
69
- st.rerun()
70
- else:
71
- st.warning("Please Enter A Prompt")
 
7
  genai.configure(api_key=GOOGLE_API_KEY)
8
 
9
  # Initialize the Generative Model
 
10
  model = genai.GenerativeModel('gemini-2.5-flash')
11
+
12
  # Function to get response from the model
13
  def get_chatbot_response(user_input):
14
  response = model.generate_content(user_input)
 
16
 
17
  # Streamlit interface
18
  st.set_page_config(page_title="Simple ChatBot", layout="centered")
 
19
  st.title("✨ Simple ChatBot ✨")
20
  st.write("Powered by Google Generative AI")
21
 
22
  if "history" not in st.session_state:
23
  st.session_state["history"] = []
24
 
25
+ # Form at the top
26
+ with st.form(key="chat_form", clear_on_submit=True):
27
+ user_input = st.text_input("", max_chars=2000, placeholder="Type your message here...")
28
+ submit_button = st.form_submit_button("Send")
29
+
30
+ if submit_button and user_input:
31
+ response = get_chatbot_response(user_input)
32
+ st.session_state.history.append((user_input, response))
33
+
34
+ # Display chat history AFTER form processing
35
  for user_message, bot_message in st.session_state.history:
36
  st.markdown(f"""
37
  <div style="
 
46
  <p style="margin: 0; font-size: 16px; line-height: 1.5;"><b>You:</b> {user_message} 😊</p>
47
  </div>
48
  """, unsafe_allow_html=True)
49
+
50
  st.markdown(f"""
51
  <div style="
52
  background-color: #e1ffc7;
 
59
  ">
60
  <p style="margin: 0; font-size: 16px; line-height: 1.5;"><b>Bot:</b> {bot_message} 🤖</p>
61
  </div>
62
+ """, unsafe_allow_html=True)