Spaces:
Paused
Paused
Update app.py
Browse files
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 |
-
|
219 |
-
|
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 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
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 |
|