Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,6 @@ import os
|
|
| 7 |
import sys
|
| 8 |
import time
|
| 9 |
import spaces
|
| 10 |
-
|
| 11 |
import gradio as gr
|
| 12 |
import torch
|
| 13 |
from PIL import Image
|
|
@@ -18,7 +17,6 @@ from transformers import (
|
|
| 18 |
LlavaOnevisionForConditionalGeneration
|
| 19 |
)
|
| 20 |
from qwen_vl_utils import process_vision_info
|
| 21 |
-
|
| 22 |
from taxonomy import policy_v1
|
| 23 |
|
| 24 |
# Set up logging
|
|
@@ -92,11 +90,28 @@ class SimpleConversation:
|
|
| 92 |
def dict(self):
|
| 93 |
# Simplified serialization for logging
|
| 94 |
image_info = "[WITH_IMAGE]" if self.current_image is not None else "[NO_IMAGE]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
return {
|
| 96 |
-
"prompt":
|
| 97 |
"image": image_info,
|
| 98 |
"response": self.current_response,
|
| 99 |
-
"messages":
|
| 100 |
}
|
| 101 |
|
| 102 |
def copy(self):
|
|
|
|
| 7 |
import sys
|
| 8 |
import time
|
| 9 |
import spaces
|
|
|
|
| 10 |
import gradio as gr
|
| 11 |
import torch
|
| 12 |
from PIL import Image
|
|
|
|
| 17 |
LlavaOnevisionForConditionalGeneration
|
| 18 |
)
|
| 19 |
from qwen_vl_utils import process_vision_info
|
|
|
|
| 20 |
from taxonomy import policy_v1
|
| 21 |
|
| 22 |
# Set up logging
|
|
|
|
| 90 |
def dict(self):
|
| 91 |
# Simplified serialization for logging
|
| 92 |
image_info = "[WITH_IMAGE]" if self.current_image is not None else "[NO_IMAGE]"
|
| 93 |
+
|
| 94 |
+
# Handle prompt which might be a tuple containing an image
|
| 95 |
+
prompt = self.get_prompt()
|
| 96 |
+
if isinstance(prompt, tuple):
|
| 97 |
+
prompt = prompt[0] # Just take the text part
|
| 98 |
+
|
| 99 |
+
# Create JSON-safe message representations
|
| 100 |
+
safe_messages = []
|
| 101 |
+
for msg in self.messages:
|
| 102 |
+
msg_prompt = msg[0]
|
| 103 |
+
# Handle tuple prompts that contain images
|
| 104 |
+
if isinstance(msg_prompt, tuple) and len(msg_prompt) > 0:
|
| 105 |
+
msg_prompt = msg_prompt[0] # Take just the text part
|
| 106 |
+
|
| 107 |
+
# Add the message with safe values
|
| 108 |
+
safe_messages.append([msg_prompt, "[RESPONSE]" if msg[1] else None])
|
| 109 |
+
|
| 110 |
return {
|
| 111 |
+
"prompt": prompt,
|
| 112 |
"image": image_info,
|
| 113 |
"response": self.current_response,
|
| 114 |
+
"messages": safe_messages
|
| 115 |
}
|
| 116 |
|
| 117 |
def copy(self):
|