Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,14 +21,18 @@ st.write("Enter text below, and the model will check if it's safe.")
|
|
21 |
user_input = st.text_area("Enter your text here:")
|
22 |
|
23 |
def check_content(text):
|
24 |
-
|
|
|
|
|
25 |
outputs = model.generate(**inputs, max_new_tokens=50)
|
26 |
-
|
|
|
|
|
27 |
|
28 |
if st.button("Check Content"):
|
29 |
if user_input:
|
30 |
result = check_content(user_input)
|
31 |
st.subheader("Moderation Result:")
|
32 |
-
st.write(result)
|
33 |
else:
|
34 |
st.warning("Please enter some text.")
|
|
|
21 |
user_input = st.text_area("Enter your text here:")
|
22 |
|
23 |
def check_content(text):
|
24 |
+
prompt = f"<|user|>\n{text}\n<|assistant|>\n" # Ensure correct formatting for input
|
25 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
26 |
+
|
27 |
outputs = model.generate(**inputs, max_new_tokens=50)
|
28 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
29 |
+
|
30 |
+
return response # Check the response format to extract category
|
31 |
|
32 |
if st.button("Check Content"):
|
33 |
if user_input:
|
34 |
result = check_content(user_input)
|
35 |
st.subheader("Moderation Result:")
|
36 |
+
st.write(result) # Print raw result first to analyze format
|
37 |
else:
|
38 |
st.warning("Please enter some text.")
|