cyrus28214 commited on
Commit
a033194
·
unverified ·
1 Parent(s): 12c4ba7
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -5,7 +5,7 @@ from threading import Thread
5
  import torch
6
  import spaces
7
 
8
- MODEL_ID = "TIGER-Lab/VL-Rethinker-7B"
9
  processor = AutoProcessor.from_pretrained(MODEL_ID, trust_remote_code=True)
10
  model = AutoModelForImageTextToText.from_pretrained(
11
  MODEL_ID,
@@ -14,7 +14,7 @@ model = AutoModelForImageTextToText.from_pretrained(
14
  ).to("cuda").eval()
15
 
16
  @spaces.GPU
17
- def respond(input_dict, chat_history):
18
  text = input_dict["text"]
19
  files = input_dict["files"]
20
 
@@ -22,7 +22,25 @@ def respond(input_dict, chat_history):
22
  current_message_images = []
23
  messages = []
24
 
25
- messages.append(chat_history)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
  current_message_images = [load_image(image) for image in files]
28
  all_images += current_message_images
 
5
  import torch
6
  import spaces
7
 
8
+ MODEL_ID = "csfufu/Revisual-R1-final"
9
  processor = AutoProcessor.from_pretrained(MODEL_ID, trust_remote_code=True)
10
  model = AutoModelForImageTextToText.from_pretrained(
11
  MODEL_ID,
 
14
  ).to("cuda").eval()
15
 
16
  @spaces.GPU
17
+ def respond(input_dict, history):
18
  text = input_dict["text"]
19
  files = input_dict["files"]
20
 
 
22
  current_message_images = []
23
  messages = []
24
 
25
+ for val in history:
26
+ if val[0]:
27
+ if isinstance(val[0], str):
28
+ messages.append({
29
+ "role": "user",
30
+ "content": [
31
+ *[{"type": "image", "image": image} for image in current_message_images],
32
+ {"type": "text", "text": val[0]},
33
+ ],
34
+ })
35
+ current_message_images = []
36
+
37
+ else:
38
+ # Load messages. These will be appended to the first user text message that comes after
39
+ current_message_images = [load_image(image) for image in val[0]]
40
+ all_images += current_message_images
41
+
42
+ if val[1]:
43
+ messages.append({"role": "assistant", "content": val[1]})
44
 
45
  current_message_images = [load_image(image) for image in files]
46
  all_images += current_message_images