Mehdi009 commited on
Commit
4a4dd26
·
verified ·
1 Parent(s): 82a7671

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """app.py
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1S9PpwawHnbXVESdJgwe2rOXa7D-H4_7R
8
+ """
9
+
10
+ !pip install -q gradio
11
+ import gradio as gr
12
+ from transformers import pipeline
13
+
14
+ # Load the fine-tuned model and tokenizer
15
+ classifier = pipeline("text-classification", model="Mehdi009/Antisemitism_Harassment_Detection")
16
+
17
+ # Function to make predictions
18
+ def predict_antisemitism(text):
19
+ result = classifier(text)
20
+ label = result[0]['label']
21
+ score = result[0]['score']
22
+ return {label: round(score, 4)}
23
+
24
+ # Create Gradio Interface
25
+ iface = gr.Interface(
26
+ fn=predict_antisemitism,
27
+ inputs=gr.Textbox(lines=2, placeholder="Enter a tweet here..."),
28
+ outputs=gr.Label(num_top_classes=2),
29
+ title="Antisemitism Harassment Detection",
30
+ description="Enter a tweet or sentence, and the model will predict whether it contains antisemitic harassment.",
31
+ examples=[
32
+ ["Jews control the media and banks."],
33
+ ["I support Israel’s right to exist and defend itself."],
34
+ ["Zionazi are ruining everything!"],
35
+ ["We need more understanding and less hate."]
36
+ ]
37
+ )
38
+
39
+ # Launch the demo
40
+ iface.launch(debug=True,share=True)