Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -43,21 +43,21 @@ def moderate(user_input, assistant_response):
|
|
43 |
result = tokenizer.decode(output[0], skip_special_tokens=True)
|
44 |
result = result.split(assistant_response)[-1].strip()
|
45 |
|
46 |
-
lines =
|
47 |
if not lines:
|
48 |
-
return "Error", "
|
49 |
|
50 |
-
first_line = lines[0]
|
51 |
if first_line == 'safe':
|
52 |
safety_status = "Safe"
|
53 |
violated_categories = "None"
|
54 |
elif first_line == 'unsafe':
|
55 |
safety_status = "Unsafe"
|
56 |
-
violated_categories = lines[1]
|
57 |
else:
|
58 |
safety_status = "Error"
|
59 |
-
violated_categories = "Invalid output"
|
60 |
-
|
61 |
return safety_status, violated_categories, result
|
62 |
|
63 |
iface = gr.Interface(
|
|
|
43 |
result = tokenizer.decode(output[0], skip_special_tokens=True)
|
44 |
result = result.split(assistant_response)[-1].strip()
|
45 |
|
46 |
+
lines = [line.strip().lower() for line in result.split('\n') if line.strip()]
|
47 |
if not lines:
|
48 |
+
return "Error", "Empty output", "No valid output from model"
|
49 |
|
50 |
+
first_line = lines[0]
|
51 |
if first_line == 'safe':
|
52 |
safety_status = "Safe"
|
53 |
violated_categories = "None"
|
54 |
elif first_line == 'unsafe':
|
55 |
safety_status = "Unsafe"
|
56 |
+
violated_categories = lines[1] if len(lines) > 1 else "Unspecified"
|
57 |
else:
|
58 |
safety_status = "Error"
|
59 |
+
violated_categories = f"Invalid output: {first_line}"
|
60 |
+
|
61 |
return safety_status, violated_categories, result
|
62 |
|
63 |
iface = gr.Interface(
|