Keyurjotaniya007 commited on
Commit
05d3701
·
verified ·
1 Parent(s): d826971

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -9
app.py CHANGED
@@ -6,27 +6,23 @@ from chatbot import (
6
  save_chat_history
7
  )
8
 
9
- # Centered Title
10
  st.markdown("""
11
  <h1 style='text-align: center;'>Welcome, ChatGPT Clone</h1>
12
  """, unsafe_allow_html=True)
13
 
14
  client = get_googlegenai_client()
15
 
16
- # Initialize session state
17
  if "googlegenai_model" not in st.session_state:
18
  st.session_state["googlegenai_model"] = get_default_model()
19
 
20
  if "messages" not in st.session_state:
21
  st.session_state.messages = load_chat_history()
22
 
23
- # Sidebar: Clear history
24
  with st.sidebar:
25
  if st.button("Delete Chat History"):
26
  st.session_state.messages = []
27
  save_chat_history([])
28
 
29
- # Show chat history
30
  for msg in st.session_state.messages:
31
  role = msg["role"]
32
  content = msg["content"]
@@ -45,9 +41,7 @@ for msg in st.session_state.messages:
45
  """, unsafe_allow_html=True)
46
  st.markdown("<div style='clear: both'></div>", unsafe_allow_html=True)
47
 
48
- # Input field
49
  if prompt := st.chat_input("Ask anything"):
50
- # Append user message
51
  st.session_state.messages.append({"role": "user", "content": prompt})
52
  st.markdown(f"""
53
  <div style='text-align: right; background-color: #f0f0f5; padding: 10px 15px; border-radius: 20px; margin: 10px 0; display: inline-block; max-width: 80%; float: right; clear: both;'>
@@ -55,7 +49,6 @@ if prompt := st.chat_input("Ask anything"):
55
  </div>
56
  """, unsafe_allow_html=True)
57
 
58
- # Stream assistant response
59
  full_response = ""
60
  response_container = st.empty()
61
  response = client.stream(st.session_state.messages)
@@ -68,7 +61,6 @@ if prompt := st.chat_input("Ask anything"):
68
  </div>
69
  """, unsafe_allow_html=True)
70
 
71
- # Final response (cleaned up)
72
  response_container.markdown(f"""
73
  <div style='text-align: left; margin: 10px 0; max-width: 80%; float: left; clear: both;'>
74
  {full_response}
@@ -76,6 +68,5 @@ if prompt := st.chat_input("Ask anything"):
76
  """, unsafe_allow_html=True)
77
  st.markdown("<div style='clear: both'></div>", unsafe_allow_html=True)
78
 
79
- # Save assistant response
80
  st.session_state.messages.append({"role": "assistant", "content": full_response})
81
  save_chat_history(st.session_state.messages)
 
6
  save_chat_history
7
  )
8
 
 
9
  st.markdown("""
10
  <h1 style='text-align: center;'>Welcome, ChatGPT Clone</h1>
11
  """, unsafe_allow_html=True)
12
 
13
  client = get_googlegenai_client()
14
 
 
15
  if "googlegenai_model" not in st.session_state:
16
  st.session_state["googlegenai_model"] = get_default_model()
17
 
18
  if "messages" not in st.session_state:
19
  st.session_state.messages = load_chat_history()
20
 
 
21
  with st.sidebar:
22
  if st.button("Delete Chat History"):
23
  st.session_state.messages = []
24
  save_chat_history([])
25
 
 
26
  for msg in st.session_state.messages:
27
  role = msg["role"]
28
  content = msg["content"]
 
41
  """, unsafe_allow_html=True)
42
  st.markdown("<div style='clear: both'></div>", unsafe_allow_html=True)
43
 
 
44
  if prompt := st.chat_input("Ask anything"):
 
45
  st.session_state.messages.append({"role": "user", "content": prompt})
46
  st.markdown(f"""
47
  <div style='text-align: right; background-color: #f0f0f5; padding: 10px 15px; border-radius: 20px; margin: 10px 0; display: inline-block; max-width: 80%; float: right; clear: both;'>
 
49
  </div>
50
  """, unsafe_allow_html=True)
51
 
 
52
  full_response = ""
53
  response_container = st.empty()
54
  response = client.stream(st.session_state.messages)
 
61
  </div>
62
  """, unsafe_allow_html=True)
63
 
 
64
  response_container.markdown(f"""
65
  <div style='text-align: left; margin: 10px 0; max-width: 80%; float: left; clear: both;'>
66
  {full_response}
 
68
  """, unsafe_allow_html=True)
69
  st.markdown("<div style='clear: both'></div>", unsafe_allow_html=True)
70
 
 
71
  st.session_state.messages.append({"role": "assistant", "content": full_response})
72
  save_chat_history(st.session_state.messages)