dlflannery commited on
Commit
5511924
·
verified ·
1 Parent(s): 2f3fad7

Update app.py

Browse files

gpt4 chats and all image analysis use gpt-4o-2024-08-06

Files changed (1) hide show
  1. app.py +21 -13
app.py CHANGED
@@ -187,12 +187,12 @@ def chat(prompt, user_window, pwd_window, past, response, gptModel, uploaded_ima
187
  response = genUsageStats(True)
188
  return [past, response, None, gptModel, uploaded_image_file]
189
  if prompt.startswith('gpt4'):
190
- gptModel = 'gpt-4o'
191
  prompt = prompt[5:]
192
  if prompt.startswith("clean"):
193
  user = prompt[6:]
194
- response = f'cleaned all .wav files for {user}'
195
- final_clean_up(user)
196
  return [past, response, None, gptModel, uploaded_image_file]
197
  if prompt.startswith('files'):
198
  (log_cnt, wav_cnt, other_cnt, others, log_list) = list_permanent_files()
@@ -204,6 +204,7 @@ def chat(prompt, user_window, pwd_window, past, response, gptModel, uploaded_ima
204
  completion = client.chat.completions.create(model=gptModel,
205
  messages=past)
206
  else:
 
207
  (completion, msg) = analyze_image(user_window, gptModel)
208
  uploaded_image_file= ''
209
  if not msg == 'ok':
@@ -301,11 +302,18 @@ def gen_speech_file_names(user, cnt):
301
  rv.append(dataDir + f'{user}_speech{i}.wav')
302
  return rv
303
 
304
- def final_clean_up(user):
305
- if user.strip().lower() == 'all':
 
 
 
306
  flist = glob(dataDir + '*_speech*.wav')
 
 
307
  else:
308
  flist = glob(dataDir + f'{user}_speech*.wav')
 
 
309
  for fpath in flist:
310
  try:
311
  os.remove(fpath)
@@ -384,13 +392,13 @@ def show_help():
384
  4.4 When done viewing image, tap the "Restart Conversation" button
385
  5. (OR) Analyze an Image you provide:
386
  5.1 Enter what you want to know about the image in the prompt window. You can include instructions
387
- to write a poem about something in the image, for example.
388
- 5.2 Tap the "Upload & Analyze Image" button.
389
- 5.3 An empty image box will appear lower left. Drag or upload image into it. It offers web cam input
390
- also but I have not tried that yet.
391
  5.4 The image should appear. This can take some time with a slow internet connection and large image.
392
  5.5 Tap the "Submit Prompt/Question" button to start the analysis. This initiates a chat dialog and
393
- you can ask follow-up questions.
394
 
395
  Hints:
396
  1. Better chat and image results are obtained by including detailed descriptions and instructions
@@ -409,7 +417,7 @@ def upload_image(prompt, user, password):
409
  return [gr.Image(visible=True, interactive=True), '']
410
 
411
  def load_image(image, user):
412
- status = 'ok'
413
  try:
414
  with open(image, 'rb') as image_file:
415
  base64_image = base64.b64encode(image_file.read()).decode('utf-8')
@@ -417,7 +425,7 @@ def load_image(image, user):
417
  with open(fpath, 'wt') as fp:
418
  fp.write(base64_image)
419
  except:
420
- status = 'Unable to create base64 image'
421
  return [fpath, status]
422
 
423
  def analyze_image(user, model):
@@ -580,7 +588,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
580
  # gpt_chooser=gr.Radio(choices=[("GPT-3.5","gpt-3.5-turbo"),("GPT-4o","gpt-4o-mini")],
581
  # value="gpt-3.5-turbo", label="GPT Model", interactive=True)
582
  button_do_image = gr.Button(value='Make Image')
583
- button_get_image = gr.Button(value='Upload & Analyze Image')
584
  submit_button = gr.Button(value="Submit Prompt/Question")
585
  speak_output = gr.Button(value="Speak Dialog", visible=False)
586
  prompt_window = gr.Textbox(label = "Prompt or Question")
 
187
  response = genUsageStats(True)
188
  return [past, response, None, gptModel, uploaded_image_file]
189
  if prompt.startswith('gpt4'):
190
+ gptModel = 'gpt-4o-2024-08-06'
191
  prompt = prompt[5:]
192
  if prompt.startswith("clean"):
193
  user = prompt[6:]
194
+ response = f'cleaned all .wav and .b64 files for {user}'
195
+ final_clean_up(user, True)
196
  return [past, response, None, gptModel, uploaded_image_file]
197
  if prompt.startswith('files'):
198
  (log_cnt, wav_cnt, other_cnt, others, log_list) = list_permanent_files()
 
204
  completion = client.chat.completions.create(model=gptModel,
205
  messages=past)
206
  else:
207
+ gptModel = 'gpt-4o-2024-08-06'
208
  (completion, msg) = analyze_image(user_window, gptModel)
209
  uploaded_image_file= ''
210
  if not msg == 'ok':
 
302
  rv.append(dataDir + f'{user}_speech{i}.wav')
303
  return rv
304
 
305
+ def final_clean_up(user, do_b64 = False):
306
+ user = user.strip().lower()
307
+ if user == 'kill':
308
+ flist = glob(dataDir + '*')
309
+ elif user == 'all':
310
  flist = glob(dataDir + '*_speech*.wav')
311
+ if do_b64:
312
+ flist.extend(glob(dataDir + '*.b64'))
313
  else:
314
  flist = glob(dataDir + f'{user}_speech*.wav')
315
+ if do_b64:
316
+ flist.append(dataDir + user + '_image.b64')
317
  for fpath in flist:
318
  try:
319
  os.remove(fpath)
 
392
  4.4 When done viewing image, tap the "Restart Conversation" button
393
  5. (OR) Analyze an Image you provide:
394
  5.1 Enter what you want to know about the image in the prompt window. You can include instructions
395
+ to write a poem about something in the image, for example. Or just say "what's in this image?"
396
+ 5.2 Tap the "Upload Image to Analyze" button.
397
+ 5.3 An empty image box will appear lower left. Drag or upload image into it. It offers web cam or camera
398
+ input also.
399
  5.4 The image should appear. This can take some time with a slow internet connection and large image.
400
  5.5 Tap the "Submit Prompt/Question" button to start the analysis. This initiates a chat dialog and
401
+ you can ask follow-up questions. However, the image is not re-analyzed for follow-up dialog.
402
 
403
  Hints:
404
  1. Better chat and image results are obtained by including detailed descriptions and instructions
 
417
  return [gr.Image(visible=True, interactive=True), '']
418
 
419
  def load_image(image, user):
420
+ status = 'OK, image is ready! Tap "Submit Prompt/Question" to start analyzing'
421
  try:
422
  with open(image, 'rb') as image_file:
423
  base64_image = base64.b64encode(image_file.read()).decode('utf-8')
 
425
  with open(fpath, 'wt') as fp:
426
  fp.write(base64_image)
427
  except:
428
+ status = 'Unable to upload image'
429
  return [fpath, status]
430
 
431
  def analyze_image(user, model):
 
588
  # gpt_chooser=gr.Radio(choices=[("GPT-3.5","gpt-3.5-turbo"),("GPT-4o","gpt-4o-mini")],
589
  # value="gpt-3.5-turbo", label="GPT Model", interactive=True)
590
  button_do_image = gr.Button(value='Make Image')
591
+ button_get_image = gr.Button(value='Upload Image to Analyze')
592
  submit_button = gr.Button(value="Submit Prompt/Question")
593
  speak_output = gr.Button(value="Speak Dialog", visible=False)
594
  prompt_window = gr.Textbox(label = "Prompt or Question")