Spaces:
Sleeping
Sleeping
RishabhBhardwaj
commited on
Commit
·
a3e8717
1
Parent(s):
e5fca1e
try3
Browse files
app.py
CHANGED
@@ -28,9 +28,8 @@ def load_image_from_url(url):
|
|
28 |
img = Image.open(BytesIO(response.content))
|
29 |
return img
|
30 |
|
31 |
-
# Evaluation
|
32 |
-
|
33 |
-
def evaluate_text(user_input, result_container):
|
34 |
if user_input:
|
35 |
# Get model and tokenizer from session state
|
36 |
tokenizer, model = st.session_state.model_and_tokenizer
|
@@ -48,13 +47,8 @@ def evaluate_text(user_input, result_container):
|
|
48 |
# Determine prediction
|
49 |
prediction = 'unsafe' if 'unsafe' in output_decoded.lower() else 'safe'
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
st.subheader("Evaluation Result:")
|
54 |
-
st.write(f"The text is evaluated as: **{prediction.upper()}**")
|
55 |
-
else:
|
56 |
-
with result_container:
|
57 |
-
st.warning("Please enter some text to evaluate.")
|
58 |
|
59 |
# Streamlit app
|
60 |
st.title("Text Safety Evaluator")
|
@@ -70,16 +64,25 @@ user_input = st.text_area("Enter the text you want to evaluate:", height=100)
|
|
70 |
result_container = st.empty()
|
71 |
|
72 |
if st.button("Evaluate"):
|
73 |
-
evaluate_text(user_input
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
-
# Add logo at the bottom center
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
81 |
|
82 |
-
# Add information about Walled Guard Advanced
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
|
|
|
28 |
img = Image.open(BytesIO(response.content))
|
29 |
return img
|
30 |
|
31 |
+
# Evaluation function
|
32 |
+
def evaluate_text(user_input):
|
|
|
33 |
if user_input:
|
34 |
# Get model and tokenizer from session state
|
35 |
tokenizer, model = st.session_state.model_and_tokenizer
|
|
|
47 |
# Determine prediction
|
48 |
prediction = 'unsafe' if 'unsafe' in output_decoded.lower() else 'safe'
|
49 |
|
50 |
+
return prediction
|
51 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
# Streamlit app
|
54 |
st.title("Text Safety Evaluator")
|
|
|
64 |
result_container = st.empty()
|
65 |
|
66 |
if st.button("Evaluate"):
|
67 |
+
prediction = evaluate_text(user_input)
|
68 |
+
if prediction:
|
69 |
+
result_container.subheader("Evaluation Result:")
|
70 |
+
result_container.write(f"The text is evaluated as: **{prediction.upper()}**")
|
71 |
+
else:
|
72 |
+
result_container.warning("Please enter some text to evaluate.")
|
73 |
|
74 |
+
# Add logo at the bottom center (only once)
|
75 |
+
if 'logo_displayed' not in st.session_state:
|
76 |
+
col1, col2, col3 = st.columns([1,2,1])
|
77 |
+
with col2:
|
78 |
+
logo_url = "https://github.com/walledai/walledeval/assets/32847115/d8b1d14f-7071-448b-8997-2eeba4c2c8f6"
|
79 |
+
logo = load_image_from_url(logo_url)
|
80 |
+
st.image(logo, use_column_width=True, width=500) # Adjust the width as needed
|
81 |
+
st.session_state.logo_displayed = True
|
82 |
|
83 |
+
# Add information about Walled Guard Advanced (only once)
|
84 |
+
if 'info_displayed' not in st.session_state:
|
85 |
+
col1, col2, col3 = st.columns([1,2,1])
|
86 |
+
with col2:
|
87 |
+
st.info("For a more performant version, check out Walled Guard Advanced. Connect with us at [email protected] for more information.")
|
88 |
+
st.session_state.info_displayed = True
|