Ubaidbhat commited on
Commit
1018eeb
1 Parent(s): b942348

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -38
app.py CHANGED
@@ -197,7 +197,14 @@ def load_counts(count_file_path):
197
 
198
  def save_counts(count_file_path, counts):
199
  with open(count_file_path, 'w') as f:
200
- json.dump(counts, f)
 
 
 
 
 
 
 
201
  def pred(user_name, image_path, audio, user_input):
202
 
203
  if user_name.strip() == "":
@@ -215,10 +222,8 @@ def pred(user_name, image_path, audio, user_input):
215
 
216
  if not os.path.exists(new_image_path):
217
  shutil.copy(image_path, new_image_path)
218
- counts = load_counts(count_file_path)
219
- counts["count"] += 1
220
- save_counts(count_file_path, counts)
221
- output = get_prompt(new_image_path, counts["count"], None, user_name)
222
  res = output["description"]
223
  with open(input_filepath, 'w') as f:
224
  f.write("Studs Terkel: " + res)
@@ -231,40 +236,35 @@ def pred(user_name, image_path, audio, user_input):
231
 
232
 
233
  if user_input.strip() != "":
234
- counts = load_counts(count_file_path)
235
- counts["count"] += 1
236
- save_counts(count_file_path, counts)
237
- with open(input_filepath, 'a') as f:
238
- f.write("\n" + user_name + ": " + user_input)
239
- with open(input_filepath, 'r') as f:
240
- content = f.read()
241
- output = get_prompt(new_image_path, counts["count"], content, user_name)
242
- res = output["question"]
243
- with open(input_filepath, 'a') as f:
244
- f.write("\n" + "Studs Terkel: "+ res)
245
- return None, "", user_input, res, transform_text_to_speech(res, user_name)
246
-
247
- # decide the path from the contents of the conversation memory.
248
- if os.path.exists(input_filepath):
249
- res = retrieve_memory(input_filepath, user_name)
250
- if res["speaker"] == "Studs Terkel":
251
- message = "Please supply text input or wait atleast 5 seconds after finishing your recording before submitting it to ensure it is fully captured. Thank you!"
252
- return None, "", "" , res["reply"], transform_text_to_speech(message, user_name)
253
- else:
254
- with open(input_filepath, 'a') as f:
255
- f.write("\n" + user_name + ": " + "I want to talk more about this photo")
256
- with open(input_filepath, 'r') as f:
257
- content = f.read()
258
- counts = load_counts(count_file_path)
259
- counts["count"] += 1
260
- save_counts(count_file_path, counts)
261
- output = get_prompt(new_image_path, counts["count"], content, user_name)
262
- res = output["question"]
263
- with open(input_filepath, 'a') as f:
264
- f.write("\n" + "Studs Terkel: "+ res)
265
- return None, "", "", res, transform_text_to_speech(res, user_name)
266
 
267
-
268
  message = "Please upload an image"
269
  return None, "", message, message, transform_text_to_speech(message, user_name)
270
 
 
197
 
198
  def save_counts(count_file_path, counts):
199
  with open(count_file_path, 'w') as f:
200
+ json.dump(counts, f)
201
+
202
+ def increment_counts(count_file_path):
203
+ counts = load_counts(count_file_path)
204
+ counts["count"] += 1
205
+ save_counts(count_file_path, counts)
206
+ return counts["count"]
207
+
208
  def pred(user_name, image_path, audio, user_input):
209
 
210
  if user_name.strip() == "":
 
222
 
223
  if not os.path.exists(new_image_path):
224
  shutil.copy(image_path, new_image_path)
225
+ iter = increment_counts(count_file_path)
226
+ output = get_prompt(new_image_path, iter, None, user_name)
 
 
227
  res = output["description"]
228
  with open(input_filepath, 'w') as f:
229
  f.write("Studs Terkel: " + res)
 
236
 
237
 
238
  if user_input.strip() != "":
239
+ iter = increment_counts(count_file_path)
240
+ with open(input_filepath, 'a') as f:
241
+ f.write("\n" + user_name + ": " + user_input)
242
+ with open(input_filepath, 'r') as f:
243
+ content = f.read()
244
+ output = get_prompt(new_image_path, iter, content, user_name)
245
+ res = output["question"]
246
+ with open(input_filepath, 'a') as f:
247
+ f.write("\n" + "Studs Terkel: "+ res)
248
+ return None, "", user_input, res, transform_text_to_speech(res, user_name)
249
+
250
+ # decide the path from the contents of the conversation memory.
251
+ if os.path.exists(input_filepath):
252
+ res = retrieve_memory(input_filepath, user_name)
253
+ if res["speaker"] == "Studs Terkel":
254
+ message = "Please supply text input or wait atleast 5 seconds after finishing your recording before submitting it to ensure it is fully captured. Thank you!"
255
+ return None, "", "" , res["reply"], transform_text_to_speech(message, user_name)
256
+ else:
257
+ with open(input_filepath, 'a') as f:
258
+ f.write("\n" + user_name + ": " + "I'd like to continue our conversation about this photograph.")
259
+ with open(input_filepath, 'r') as f:
260
+ content = f.read()
261
+ iter = increment_counts(count_file_path)
262
+ output = get_prompt(new_image_path, iter, content, user_name)
263
+ res = output["question"]
264
+ with open(input_filepath, 'a') as f:
265
+ f.write("\n" + "Studs Terkel: "+ res)
266
+ return None, "", "I'd like to continue our conversation about this photograph.", res, transform_text_to_speech(res, user_name)
 
 
 
 
267
 
 
268
  message = "Please upload an image"
269
  return None, "", message, message, transform_text_to_speech(message, user_name)
270