Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -22,7 +22,7 @@ model.to("cuda:0")
|
|
22 |
|
23 |
@spaces.GPU
|
24 |
def bot_streaming(message, history):
|
25 |
-
|
26 |
if message["files"]:
|
27 |
image = message["files"][-1]["path"]
|
28 |
else:
|
@@ -32,21 +32,21 @@ def bot_streaming(message, history):
|
|
32 |
image_turn = i
|
33 |
|
34 |
if len(history) > 0 and image is not None:
|
35 |
-
|
36 |
-
|
37 |
for human, assistant in history[2:]:
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
elif len(history) > 0 and image is None:
|
42 |
for human, assistant in history:
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
elif len(history) == 0 and image is not None:
|
47 |
-
|
48 |
elif len(history) == 0 and image is None:
|
49 |
-
|
50 |
|
51 |
# if image is None:
|
52 |
# gr.Error("You need to upload an image for LLaVA to work.")
|
|
|
22 |
|
23 |
@spaces.GPU
|
24 |
def bot_streaming(message, history):
|
25 |
+
messages = []
|
26 |
if message["files"]:
|
27 |
image = message["files"][-1]["path"]
|
28 |
else:
|
|
|
32 |
image_turn = i
|
33 |
|
34 |
if len(history) > 0 and image is not None:
|
35 |
+
messages.append({"role": "user", "content": f'<image>\n{history[1][0]}'})
|
36 |
+
messages.append({"role": "assistant", "content": history[1][1] })
|
37 |
for human, assistant in history[2:]:
|
38 |
+
messages.append({"role": "user", "content": human })
|
39 |
+
messages.append({"role": "assistant", "content": assistant })
|
40 |
+
messages.append({"role": "user", "content": message['text']})
|
41 |
elif len(history) > 0 and image is None:
|
42 |
for human, assistant in history:
|
43 |
+
messages.append({"role": "user", "content": human })
|
44 |
+
messages.append({"role": "assistant", "content": assistant })
|
45 |
+
messages.append({"role": "user", "content": message['text']})
|
46 |
elif len(history) == 0 and image is not None:
|
47 |
+
messages.append({"role": "user", "content": f"<image>\n{message['text']}"})
|
48 |
elif len(history) == 0 and image is None:
|
49 |
+
messages.append({"role": "user", "content": message['text'] })
|
50 |
|
51 |
# if image is None:
|
52 |
# gr.Error("You need to upload an image for LLaVA to work.")
|