Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- gradio_app.py +10 -9
gradio_app.py
CHANGED
@@ -37,22 +37,23 @@ def load_chat(
|
|
37 |
history = ChatInterface._tuples_to_messages(history)
|
38 |
elif len(history) > 0 and isinstance(history[0], dict):
|
39 |
hist = []
|
40 |
-
|
41 |
for i, h in enumerate(history):
|
42 |
-
if skip:
|
43 |
-
skip = False
|
44 |
-
continue
|
45 |
content = h.get("content", [])
|
46 |
role = h.get("role", "")
|
|
|
47 |
if isinstance(content, tuple):
|
48 |
src_path = content[0]
|
49 |
-
|
50 |
else:
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
if i < len(history) - 1 and role == history[i + 1].get("role", ""):
|
54 |
-
|
55 |
-
skip = True
|
56 |
history = hist
|
57 |
files = message.get('files', [])
|
58 |
content = [
|
|
|
37 |
history = ChatInterface._tuples_to_messages(history)
|
38 |
elif len(history) > 0 and isinstance(history[0], dict):
|
39 |
hist = []
|
40 |
+
merge = False
|
41 |
for i, h in enumerate(history):
|
|
|
|
|
|
|
42 |
content = h.get("content", [])
|
43 |
role = h.get("role", "")
|
44 |
+
ct = []
|
45 |
if isinstance(content, tuple):
|
46 |
src_path = content[0]
|
47 |
+
ct = [{"type": "image_url", "image_url": {"url": get_gradio_url(src_path)}}]
|
48 |
else:
|
49 |
+
ct = [{"type": "text", "text": content}]
|
50 |
+
if merge:
|
51 |
+
hist[-1]["content"].append(ct)
|
52 |
+
merge = False
|
53 |
+
else:
|
54 |
+
hist.append({"role": role, "content": ct})
|
55 |
if i < len(history) - 1 and role == history[i + 1].get("role", ""):
|
56 |
+
merge = True
|
|
|
57 |
history = hist
|
58 |
files = message.get('files', [])
|
59 |
content = [
|