Spaces:
Runtime error
Runtime error
Zekun Wu
commited on
Commit
•
0add53e
1
Parent(s):
f18d3e1
update
Browse files- app.py +10 -2
- bias_detector/bias_detector.py +2 -4
app.py
CHANGED
@@ -3,7 +3,14 @@ from bias_detector import Detector
|
|
3 |
|
4 |
st.title("Multidimensional Multilevel Bias Detection")
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def format_results(results):
|
8 |
formatted = ""
|
9 |
for result in results:
|
@@ -40,7 +47,8 @@ if st.button("Load Models"):
|
|
40 |
else:
|
41 |
st.text("Failed to load models. Please check the server and/or model parameters.")
|
42 |
|
43 |
-
|
|
|
44 |
|
45 |
if st.button("Detect"):
|
46 |
results = detector.predict([target_sentence])
|
|
|
3 |
|
4 |
st.title("Multidimensional Multilevel Bias Detection")
|
5 |
|
6 |
+
EXAMPLES = {
|
7 |
+
"Gender": "The stepfather burst into little Mikey's room with whiskey on his breath. But soon thereafter, the boy was greeted with a big surprise as many other family members plowed into his room with birthday card & presents.",
|
8 |
+
"Religion": "The muslim roisterer in the news was out on new year's eve making the rounds.",
|
9 |
+
"Race": "I had to travel to Qatar for work. It was hot, smelly, and oppressive.",
|
10 |
+
"Profession": "The clerk was working the cash register. She was from some Arab nation.",
|
11 |
+
"Input your own": ""
|
12 |
+
# Add more examples as needed
|
13 |
+
}
|
14 |
def format_results(results):
|
15 |
formatted = ""
|
16 |
for result in results:
|
|
|
47 |
else:
|
48 |
st.text("Failed to load models. Please check the server and/or model parameters.")
|
49 |
|
50 |
+
example_type = st.selectbox("Choose an example type:", list(EXAMPLES.keys()))
|
51 |
+
target_sentence = st.text_input("Input the sentence you want to detect:", value=EXAMPLES[example_type])
|
52 |
|
53 |
if st.button("Detect"):
|
54 |
results = detector.predict([target_sentence])
|
bias_detector/bias_detector.py
CHANGED
@@ -67,13 +67,11 @@ class Detector:
|
|
67 |
# Create the API endpoint from the model path
|
68 |
self.API_URL = f"https://api-inference.huggingface.co/models/{self.model_path}"
|
69 |
API_token = os.getenv("BIAS_DETECTOR_API_KEY")
|
|
|
|
|
70 |
# Add authorization token (if required)
|
71 |
self.headers = {"Authorization": f"Bearer {API_token}"} # Replace `your_api_token` with your token
|
72 |
|
73 |
-
import time
|
74 |
-
|
75 |
-
import time
|
76 |
-
|
77 |
def query(self, payload, max_retries=5, wait_time=5):
|
78 |
retries = 0
|
79 |
|
|
|
67 |
# Create the API endpoint from the model path
|
68 |
self.API_URL = f"https://api-inference.huggingface.co/models/{self.model_path}"
|
69 |
API_token = os.getenv("BIAS_DETECTOR_API_KEY")
|
70 |
+
#API_token = "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"
|
71 |
+
|
72 |
# Add authorization token (if required)
|
73 |
self.headers = {"Authorization": f"Bearer {API_token}"} # Replace `your_api_token` with your token
|
74 |
|
|
|
|
|
|
|
|
|
75 |
def query(self, payload, max_retries=5, wait_time=5):
|
76 |
retries = 0
|
77 |
|