derektan commited on
Commit
fed0b3b
·
1 Parent(s): 44fb3df

Alowed for text inputs with special chars

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -216,9 +216,9 @@ def inference(input_str, input_image):
216
 
217
  print("input_str: ", input_str, "input_image: ", input_image)
218
 
219
- ## input valid check
220
- if not re.match(r"^[A-Za-z ,.!?\'\"]+$", input_str) or len(input_str) < 1:
221
- output_str = f"[Error] Invalid input: {input_str}"
222
  # Create a red placeholder image to indicate an error
223
  output_image = np.zeros((128, 128, 3), dtype=np.uint8)
224
  output_image[:] = (0, 0, 0) # Red color in RGB
 
216
 
217
  print("input_str: ", input_str, "input_image: ", input_image)
218
 
219
+ ## basic validity check: non-empty and reasonable length only
220
+ if len(input_str.strip()) == 0 or len(input_str) > 1024:
221
+ output_str = f"[Error] Invalid input length: {len(input_str)}"
222
  # Create a red placeholder image to indicate an error
223
  output_image = np.zeros((128, 128, 3), dtype=np.uint8)
224
  output_image[:] = (0, 0, 0) # Red color in RGB