Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ model = AutoModelForCausalLM.from_pretrained("q-future/co-instruct-preview",
|
|
11 |
attn_implementation="eager",
|
12 |
device_map={"":"cuda:0"})
|
13 |
|
14 |
-
def chat(message, history, image_1, image_2):
|
15 |
print(history)
|
16 |
if history:
|
17 |
if image_1 is not None and image_2 is None:
|
@@ -21,18 +21,29 @@ def chat(message, history, image_1, image_2):
|
|
21 |
message = past_message + "USER:" + message + " ASSISTANT:"
|
22 |
images = [image_1]
|
23 |
if image_1 is not None and image_2 is not None:
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
else:
|
30 |
if image_1 is not None and image_2 is None:
|
31 |
message = "USER: The image: <|image|> " + message + " ASSISTANT:"
|
32 |
images = [image_1]
|
33 |
if image_1 is not None and image_2 is not None:
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
36 |
|
37 |
print(message)
|
38 |
|
@@ -55,7 +66,8 @@ with gr.Blocks(title="img") as demo:
|
|
55 |
""")
|
56 |
gr.Markdown(title_markdown)
|
57 |
with gr.Row():
|
58 |
-
input_img_1 = gr.Image(type='pil', label="Image 1 (
|
59 |
-
input_img_2 = gr.Image(type='pil', label="Image 2 (
|
60 |
-
|
|
|
61 |
demo.launch(share=True)
|
|
|
11 |
attn_implementation="eager",
|
12 |
device_map={"":"cuda:0"})
|
13 |
|
14 |
+
def chat(message, history, image_1, image_2, image_3):
|
15 |
print(history)
|
16 |
if history:
|
17 |
if image_1 is not None and image_2 is None:
|
|
|
21 |
message = past_message + "USER:" + message + " ASSISTANT:"
|
22 |
images = [image_1]
|
23 |
if image_1 is not None and image_2 is not None:
|
24 |
+
if image_3 is None:
|
25 |
+
past_message = "USER: The first image: <|image|>\nThe second image: <|image|>" + history[0][0] + " ASSISTANT:" + history[0][1] + "</s>"
|
26 |
+
for i in range((len(history) - 1)):
|
27 |
+
past_message += "USER:" + history[i][0] + " ASSISTANT:" + history[i][1] + "</s>"
|
28 |
+
message = past_message + "USER:" + message + " ASSISTANT:"
|
29 |
+
images = [image_1, image_2]
|
30 |
+
else:
|
31 |
+
past_message = "USER: The first image: <|image|>\nThe second image: <|image|>\nThe third image:<|image|>" + history[0][0] + " ASSISTANT:" + history[0][1] + "</s>"
|
32 |
+
for i in range((len(history) - 1)):
|
33 |
+
past_message += "USER:" + history[i][0] + " ASSISTANT:" + history[i][1] + "</s>"
|
34 |
+
message = past_message + "USER:" + message + " ASSISTANT:"
|
35 |
+
images = [image_1, image_2, image_3]
|
36 |
else:
|
37 |
if image_1 is not None and image_2 is None:
|
38 |
message = "USER: The image: <|image|> " + message + " ASSISTANT:"
|
39 |
images = [image_1]
|
40 |
if image_1 is not None and image_2 is not None:
|
41 |
+
if image_3 is None:
|
42 |
+
message = "USER: The first image: <|image|>\nThe second image: <|image|>" + message + " ASSISTANT:"
|
43 |
+
images = [image_1, image_2]
|
44 |
+
else:
|
45 |
+
message = "USER: The first image: <|image|>\nThe second image: <|image|>\nThe third image:<|image|>" + message + " ASSISTANT:"
|
46 |
+
images = [image_1, image_2, image_3]
|
47 |
|
48 |
print(message)
|
49 |
|
|
|
66 |
""")
|
67 |
gr.Markdown(title_markdown)
|
68 |
with gr.Row():
|
69 |
+
input_img_1 = gr.Image(type='pil', label="Image 1 (First image)")
|
70 |
+
input_img_2 = gr.Image(type='pil', label="Image 2 (Second image)")
|
71 |
+
input_img_2 = gr.Image(type='pil', label="Image 3 (Third image)")
|
72 |
+
gr.ChatInterface(fn = chat, additional_inputs=[input_img_1, input_img_2, input_img_3])
|
73 |
demo.launch(share=True)
|