Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -91,15 +91,20 @@ def bot_streaming(message, history, max_new_tokens=2048):
|
|
91 |
context = f"\nDocument context:\n{doc_state.current_doc_text}" if doc_state.current_doc_text else ""
|
92 |
current_msg = f"{txt}{context}"
|
93 |
messages.append({"role": "user", "content": [{"type": "text", "text": current_msg}, {"type": "image"}]})
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
inputs = processor(
|
97 |
text=texts,
|
98 |
images=doc_state.current_doc_images[0:1], # Only use first image
|
99 |
return_tensors="pt"
|
100 |
).to("cuda")
|
101 |
else:
|
102 |
-
messages.append({"role": "user", "content": [{"type": "text", "text": txt}]})
|
103 |
inputs = processor(text=texts, return_tensors="pt").to("cuda")
|
104 |
|
105 |
streamer = TextIteratorStreamer(processor, skip_special_tokens=True, skip_prompt=True)
|
|
|
91 |
context = f"\nDocument context:\n{doc_state.current_doc_text}" if doc_state.current_doc_text else ""
|
92 |
current_msg = f"{txt}{context}"
|
93 |
messages.append({"role": "user", "content": [{"type": "text", "text": current_msg}, {"type": "image"}]})
|
94 |
+
else:
|
95 |
+
messages.append({"role": "user", "content": [{"type": "text", "text": txt}]})
|
96 |
+
|
97 |
+
# Apply chat template to messages
|
98 |
+
texts = processor.apply_chat_template(messages, add_generation_prompt=True)
|
99 |
+
|
100 |
+
# Process inputs based on whether we have images
|
101 |
+
if doc_state.current_doc_images:
|
102 |
inputs = processor(
|
103 |
text=texts,
|
104 |
images=doc_state.current_doc_images[0:1], # Only use first image
|
105 |
return_tensors="pt"
|
106 |
).to("cuda")
|
107 |
else:
|
|
|
108 |
inputs = processor(text=texts, return_tensors="pt").to("cuda")
|
109 |
|
110 |
streamer = TextIteratorStreamer(processor, skip_special_tokens=True, skip_prompt=True)
|