Spaces:
Running
on
Zero
Running
on
Zero
Handle history
Browse files
app.py
CHANGED
@@ -47,11 +47,20 @@ def bot_streaming(message, history):
|
|
47 |
elif len(message.files) > 1:
|
48 |
image = [msg.path for msg in message.files]
|
49 |
else:
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
if message.files is None:
|
57 |
gr.Error("You need to upload an image or video for LLaVA to work.")
|
|
|
47 |
elif len(message.files) > 1:
|
48 |
image = [msg.path for msg in message.files]
|
49 |
else:
|
50 |
+
|
51 |
+
def has_file_data(lst):
|
52 |
+
return any(isinstance(item, FileData) for sublist in lst if isinstance(sublist, tuple) for item in sublist)
|
53 |
+
|
54 |
+
def extract_paths(lst):
|
55 |
+
return [item.path for sublist in lst if isinstance(sublist, tuple) for item in sublist if isinstance(item, FileData)]
|
56 |
+
|
57 |
+
latest_text_only_index = -1
|
58 |
+
|
59 |
+
for i, item in enumerate(history):
|
60 |
+
if all(isinstance(sub_item, str) for sub_item in item):
|
61 |
+
latest_text_only_index = i
|
62 |
+
|
63 |
+
image = [path for i, item in enumerate(history) if i < latest_text_only_index and has_file_data(item) for path in extract_paths(item)]
|
64 |
|
65 |
if message.files is None:
|
66 |
gr.Error("You need to upload an image or video for LLaVA to work.")
|