Spaces:
Sleeping
Sleeping
| # -*- 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) |