Spaces:
Running
on
Zero
Running
on
Zero
Joseph Pollack
commited on
return string when string directly without encoding tokens
Browse files
app.py
CHANGED
|
@@ -107,15 +107,24 @@ class LOperatorDemo:
|
|
| 107 |
)
|
| 108 |
logger.info(f"Processor output type: {type(inputs)}")
|
| 109 |
|
| 110 |
-
#
|
| 111 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
logger.warning("apply_chat_template did not return a tensor, attempting to convert...")
|
| 113 |
if isinstance(inputs, (list, tuple)):
|
| 114 |
inputs = torch.tensor(inputs)
|
| 115 |
else:
|
| 116 |
-
# If it's
|
| 117 |
-
logger.
|
| 118 |
-
return
|
| 119 |
|
| 120 |
inputs = inputs.to(self.model.device)
|
| 121 |
logger.info(f"Inputs shape: {inputs.shape}, device: {inputs.device}")
|
|
|
|
| 107 |
)
|
| 108 |
logger.info(f"Processor output type: {type(inputs)}")
|
| 109 |
|
| 110 |
+
# If processor returns a string, just return it directly
|
| 111 |
+
if isinstance(inputs, str):
|
| 112 |
+
logger.info("Processor returned string, returning directly...")
|
| 113 |
+
return inputs
|
| 114 |
+
|
| 115 |
+
# Handle other return types
|
| 116 |
+
if isinstance(inputs, dict):
|
| 117 |
+
# If processor returns a dict, extract input_ids
|
| 118 |
+
logger.info("Processor returned dict, extracting input_ids...")
|
| 119 |
+
inputs = inputs["input_ids"]
|
| 120 |
+
elif not isinstance(inputs, torch.Tensor):
|
| 121 |
logger.warning("apply_chat_template did not return a tensor, attempting to convert...")
|
| 122 |
if isinstance(inputs, (list, tuple)):
|
| 123 |
inputs = torch.tensor(inputs)
|
| 124 |
else:
|
| 125 |
+
# If it's an unexpected type, return the string directly
|
| 126 |
+
logger.warning(f"Unexpected input type: {type(inputs)}, returning as string")
|
| 127 |
+
return str(inputs)
|
| 128 |
|
| 129 |
inputs = inputs.to(self.model.device)
|
| 130 |
logger.info(f"Inputs shape: {inputs.shape}, device: {inputs.device}")
|