File size: 1,216 Bytes
4a4dd26
 
 
 
 
 
 
 
 
 
 
 
 
1d0aec2
4a4dd26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-
"""app.py

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1S9PpwawHnbXVESdJgwe2rOXa7D-H4_7R
"""

import gradio as gr
from transformers import pipeline

# Load the fine-tuned model and tokenizer
classifier = pipeline("text-classification", model="Mehdi009/Antisemitism_Harassment_Detection_Model")

# Function to make predictions
def predict_antisemitism(text):
    result = classifier(text)
    label = result[0]['label']
    score = result[0]['score']
    return {label: round(score, 4)}

# Create Gradio Interface
iface = gr.Interface(
    fn=predict_antisemitism,
    inputs=gr.Textbox(lines=2, placeholder="Enter a tweet here..."),
    outputs=gr.Label(num_top_classes=2),
    title="Antisemitism Harassment Detection",
    description="Enter a tweet or sentence, and the model will predict whether it contains antisemitic harassment.",
    examples=[
        ["Jews control the media and banks."],
        ["I support Israel’s right to exist and defend itself."],
        ["Zionazi are ruining everything!"],
        ["We need more understanding and less hate."]
    ]
)

# Launch the demo
iface.launch(debug=True,share=True)