DocUA commited on
Commit
66a4db3
·
1 Parent(s): 461adca

Fix input validation: add specific error messages for empty URL and text inputs

Browse files
Files changed (1) hide show
  1. interface.py +16 -4
interface.py CHANGED
@@ -187,7 +187,9 @@ async def process_input(
187
  input_type = "text"
188
  input_text = ""
189
 
190
- if input_method == "Завантаження файлу" and file_input:
 
 
191
  try:
192
  with open(file_input.name, 'r', encoding='utf-8') as file:
193
  input_text = file.read()
@@ -197,11 +199,15 @@ async def process_input(
197
  elif input_method == "URL посилання":
198
  input_type = "url"
199
  input_text = url_input
 
 
200
  else:
201
  input_text = text_input
 
 
202
 
203
  if not input_text:
204
- return "Помилка: Текст не може бути порожнім", None, session_id
205
 
206
  # Get custom prompts from session
207
  manager = get_session_manager()
@@ -253,7 +259,9 @@ async def process_raw_text_search(text, url, file, method, state_lp_json):
253
  """Process raw text search and update necessary states."""
254
  try:
255
  input_text = ""
256
- if method == "Завантаження файлу" and file:
 
 
257
  try:
258
  with open(file.name, 'r', encoding='utf-8') as f:
259
  input_text = f.read()
@@ -262,11 +270,15 @@ async def process_raw_text_search(text, url, file, method, state_lp_json):
262
  input_text = f.read()
263
  elif method == "URL посилання":
264
  input_text = url
 
 
265
  else:
266
  input_text = text
 
 
267
 
268
  if not input_text:
269
- return "Помилка: Порожній текст", None, state_lp_json
270
 
271
  input_text = clean_text(input_text)
272
 
 
187
  input_type = "text"
188
  input_text = ""
189
 
190
+ if input_method == "Завантаження файлу":
191
+ if not file_input:
192
+ return "❌ Помилка: Будь ласка, завантажте файл", None, session_id
193
  try:
194
  with open(file_input.name, 'r', encoding='utf-8') as file:
195
  input_text = file.read()
 
199
  elif input_method == "URL посилання":
200
  input_type = "url"
201
  input_text = url_input
202
+ if not input_text or not input_text.strip():
203
+ return "❌ Помилка: Будь ласка, введіть URL посилання на судове рішення", None, session_id
204
  else:
205
  input_text = text_input
206
+ if not input_text or not input_text.strip():
207
+ return "❌ Помилка: Будь ласка, введіть текст судового рішення", None, session_id
208
 
209
  if not input_text:
210
+ return "Помилка: Текст не може бути порожнім", None, session_id
211
 
212
  # Get custom prompts from session
213
  manager = get_session_manager()
 
259
  """Process raw text search and update necessary states."""
260
  try:
261
  input_text = ""
262
+ if method == "Завантаження файлу":
263
+ if not file:
264
+ return "❌ Помилка: Будь ласка, завантажте файл", None, state_lp_json
265
  try:
266
  with open(file.name, 'r', encoding='utf-8') as f:
267
  input_text = f.read()
 
270
  input_text = f.read()
271
  elif method == "URL посилання":
272
  input_text = url
273
+ if not input_text or not input_text.strip():
274
+ return "❌ Помилка: Будь ласка, введіть URL посилання на судове рішення", None, state_lp_json
275
  else:
276
  input_text = text
277
+ if not input_text or not input_text.strip():
278
+ return "❌ Помилка: Будь ласка, введіть текст судового рішення", None, state_lp_json
279
 
280
  if not input_text:
281
+ return "Помилка: Порожній текст", None, state_lp_json
282
 
283
  input_text = clean_text(input_text)
284