dipta007 commited on
Commit
69e0201
1 Parent(s): 3643ac5

update split

Browse files
Files changed (2) hide show
  1. app.py +1 -4
  2. utils.py +1 -1
app.py CHANGED
@@ -125,8 +125,7 @@ def push_message(role, content, images=None):
125
  st.session_state.messages.append(message)
126
  return message
127
 
128
- chat_input_disabled = False
129
- if prompt := st.chat_input("Type a message", key="chat_input", disabled=chat_input_disabled):
130
  push_message("user", prompt, images)
131
  with st.chat_message("user"):
132
  st.markdown(prompt)
@@ -141,7 +140,6 @@ if prompt := st.chat_input("Type a message", key="chat_input", disabled=chat_inp
141
  {"role": m["role"], "content": m["content"]}
142
  for m in st.session_state.messages
143
  ]
144
- chat_input_disabled = True
145
  stream = client.chat.completions.create(
146
  model="gpt-4-vision-preview",
147
  messages=messages,
@@ -154,5 +152,4 @@ if prompt := st.chat_input("Type a message", key="chat_input", disabled=chat_inp
154
 
155
  push_message("assistant", response)
156
  calculate_cost()
157
- chat_input_disabled = False
158
  clear_uploader()
 
125
  st.session_state.messages.append(message)
126
  return message
127
 
128
+ if prompt := st.chat_input("Type a message", key="chat_input"):
 
129
  push_message("user", prompt, images)
130
  with st.chat_message("user"):
131
  st.markdown(prompt)
 
140
  {"role": m["role"], "content": m["content"]}
141
  for m in st.session_state.messages
142
  ]
 
143
  stream = client.chat.completions.create(
144
  model="gpt-4-vision-preview",
145
  messages=messages,
 
152
 
153
  push_message("assistant", response)
154
  calculate_cost()
 
155
  clear_uploader()
utils.py CHANGED
@@ -23,7 +23,7 @@ def im_2_b64(image):
23
 
24
  def calculate_cost():
25
  def get_text_cost(text, unit_cost):
26
- num_of_words = len(text.split(" "))
27
  tokens = max(1000.0 * num_of_words / 750.0, 0.0)
28
  tokens = tokens / 1000.0
29
  cost = tokens * unit_cost
 
23
 
24
  def calculate_cost():
25
  def get_text_cost(text, unit_cost):
26
+ num_of_words = len(text.split())
27
  tokens = max(1000.0 * num_of_words / 750.0, 0.0)
28
  tokens = tokens / 1000.0
29
  cost = tokens * unit_cost