IAMTFRMZA commited on
Commit
7ac34ac
·
verified ·
1 Parent(s): 6dd8aa5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -72,15 +72,16 @@ else:
72
 
73
  # Display chat history with avatars
74
  for i, msg in enumerate(st.session_state["messages"]):
75
- avatar_url = "https://www.carfind.co.za/images/Carfind-Icon.svg" if msg["role"] == "assistant" else None
76
- message(
77
- msg["content"],
78
- is_user=(msg["role"] == "user"),
79
- key=str(i),
80
- avatar_style="adventurer" if msg["role"] == "user" else None,
81
- seed="user-seed" if msg["role"] == "user" else None,
82
- avatar_url=avatar_url
83
- )
 
84
 
85
  col_input, col_clear = st.columns([10, 1])
86
 
@@ -94,7 +95,6 @@ else:
94
 
95
  # Handle OpenAI assistant (with loop protection)
96
  if user_input and openai_key:
97
- # Avoid duplicate messages triggering loops
98
  if len(st.session_state.messages) == 0 or user_input != st.session_state.messages[-1]["content"]:
99
  st.session_state.messages.append({"role": "user", "content": user_input})
100
 
@@ -136,7 +136,6 @@ else:
136
  messages_response = client.beta.threads.messages.list(thread_id=thread_id)
137
  assistant_reply = messages_response.data[0].content[0].text.value
138
 
139
- # Prevent infinite repetition by ignoring if assistant echoes input
140
  if assistant_reply.strip().lower() != user_input.strip().lower():
141
  st.session_state.messages.append({"role": "assistant", "content": assistant_reply})
142
  save_transcript(st.session_state.messages)
 
72
 
73
  # Display chat history with avatars
74
  for i, msg in enumerate(st.session_state["messages"]):
75
+ if msg["role"] == "assistant":
76
+ st.markdown(f'<img src="https://www.carfind.co.za/images/Carfind-Icon.svg" width="30" style="vertical-align: middle;"> <strong>Carfind Assistant:</strong> {msg["content"]}', unsafe_allow_html=True)
77
+ else:
78
+ message(
79
+ msg["content"],
80
+ is_user=True,
81
+ key=str(i),
82
+ avatar_style="adventurer",
83
+ seed="user-seed"
84
+ )
85
 
86
  col_input, col_clear = st.columns([10, 1])
87
 
 
95
 
96
  # Handle OpenAI assistant (with loop protection)
97
  if user_input and openai_key:
 
98
  if len(st.session_state.messages) == 0 or user_input != st.session_state.messages[-1]["content"]:
99
  st.session_state.messages.append({"role": "user", "content": user_input})
100
 
 
136
  messages_response = client.beta.threads.messages.list(thread_id=thread_id)
137
  assistant_reply = messages_response.data[0].content[0].text.value
138
 
 
139
  if assistant_reply.strip().lower() != user_input.strip().lower():
140
  st.session_state.messages.append({"role": "assistant", "content": assistant_reply})
141
  save_transcript(st.session_state.messages)