mskov commited on
Commit
ec89d20
·
1 Parent(s): 5d26119

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -2
app.py CHANGED
@@ -1,6 +1,32 @@
1
  import evaluate
2
  from evaluate.utils import launch_gradio_widget
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
 
 
 
 
 
 
 
 
4
 
5
- module = evaluate.load("toxicity")
6
- launch_gradio_widget(module)
 
1
  import evaluate
2
  from evaluate.utils import launch_gradio_widget
3
+ import evaluate
4
+ from evaluate.utils import launch_gradio_widget
5
+ import gradio as gr
6
+
7
+ # Define the list of available models
8
+ available_models = {
9
+ "unitary/toxic-bert": "Bert Base Model",
10
+ "facebook/roberta-hate-speech-dynabench-r4-target": "Facebook Model",
11
+ "mskov/roberta-base-toxicity": "Roberta Finetuned Model",
12
+ "mskov/distilbert-base-toxicity" : "Distillbert Finetuned Model"
13
+ }
14
+
15
+ # Create a Gradio interface with a radio button to select the model
16
+ def classify_toxicity(text, selected_model):
17
+ # Load the selected model
18
+ module = evaluate.load("toxicity", selected_model)
19
+ results = module.compute(predictions=[text])
20
+ toxicity_score = results["toxicity"][0]
21
+ return f"Toxicity Score ({available_models[selected_model]}): {toxicity_score:.4f}"
22
 
23
+ iface = gr.Interface(
24
+ fn=classify_toxicity,
25
+ inputs=["text", gr.Radio(available_models, type="value", label="Select Model")],
26
+ outputs="text",
27
+ live=True,
28
+ title="Toxicity Classifier",
29
+ description="Select a model and enter text to classify its toxicity.",
30
+ )
31
 
32
+ launch_gradio_widget(iface)