Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,28 +53,19 @@ def stream_chat(message, history: list, temperature: float, max_new_tokens: int)
|
|
| 53 |
print(f'history is - {history}')
|
| 54 |
conversation = []
|
| 55 |
if message["files"]:
|
| 56 |
-
|
| 57 |
-
if isinstance(image_path, dict):
|
| 58 |
-
mage_path = image_path["path"]
|
| 59 |
-
image = Image.open(image_path)
|
| 60 |
conversation.append({"role": "user", "content": f"<|image_1|>\n{message['text']}"})
|
| 61 |
else:
|
| 62 |
if len(history) == 0:
|
| 63 |
raise gr.Error("Please upload an image first.")
|
| 64 |
image = None
|
| 65 |
else:
|
| 66 |
-
|
| 67 |
-
image_path = history[0][0][0]
|
| 68 |
-
else:
|
| 69 |
-
image_path = history[0][0]
|
| 70 |
-
image = Image.open(image_path)
|
| 71 |
for prompt, answer in history:
|
| 72 |
if answer is None:
|
| 73 |
-
conversation.extend([{"role": "user", "content":""}])
|
| 74 |
-
conversation[0]['content'] = f"<|image_1|>\n{prompt}"
|
| 75 |
conversation.extend([{"role": "user", "content": prompt}, {"role": "assistant", "content": answer}])
|
| 76 |
-
|
| 77 |
-
|
| 78 |
print(f"Conversation is -\n{conversation}")
|
| 79 |
inputs = processor.tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
|
| 80 |
inputs_ids = processor(inputs, image, return_tensors="pt").to(0)
|
|
|
|
| 53 |
print(f'history is - {history}')
|
| 54 |
conversation = []
|
| 55 |
if message["files"]:
|
| 56 |
+
image = Image.open(message["files"][-1])
|
|
|
|
|
|
|
|
|
|
| 57 |
conversation.append({"role": "user", "content": f"<|image_1|>\n{message['text']}"})
|
| 58 |
else:
|
| 59 |
if len(history) == 0:
|
| 60 |
raise gr.Error("Please upload an image first.")
|
| 61 |
image = None
|
| 62 |
else:
|
| 63 |
+
image = Image.open(history[0][0][0])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
for prompt, answer in history:
|
| 65 |
if answer is None:
|
| 66 |
+
conversation.extend([{"role": "user", "content":"<|image_1|>"},{"role": "assistant", "content": ""}])
|
|
|
|
| 67 |
conversation.extend([{"role": "user", "content": prompt}, {"role": "assistant", "content": answer}])
|
| 68 |
+
conversation.append({"role": "user", "content": message['text']})
|
|
|
|
| 69 |
print(f"Conversation is -\n{conversation}")
|
| 70 |
inputs = processor.tokenizer.apply_chat_template(conversation, tokenize=False, add_generation_prompt=True)
|
| 71 |
inputs_ids = processor(inputs, image, return_tensors="pt").to(0)
|