Download app.py from Qptimus/merhaba: direct link, hf CLI and curl.
- Browser
- Download file 778 Bytes
-
https://huggingface.co/spaces/Qptimus/merhaba/resolve/main/app.py
- Command line
-
hf download hf://spaces/Qptimus/merhaba/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Qptimus/merhaba/resolve/main/app.py
778 Bytes
| # app.py | |
| import gradio as gr | |
| from transformers import pipeline | |
| # Türkçe toksisite modeli | |
| model_name = "cagrigungor/turkishtoxic-classifier" | |
| classifier = pipeline("text-classification", model=model_name) | |
| # Moderasyon fonksiyonu | |
| def analyze_toxicity(text): | |
| result = classifier(text) | |
| # LABEL_1 veya 'toxic' etiketini al | |
| toxic_score = max([item['score'] for item in result if item['label'].lower() in ['label_1','toxic']], default=0) | |
| return {"toxicityScore": toxic_score, "isModerated": toxic_score < 0.7} | |
| # Gradio Interface | |
| demo = gr.Interface( | |
| fn=analyze_toxicity, | |
| inputs=gr.Textbox(), | |
| outputs=gr.Label(), | |
| api_name="analyze_toxicity", # Endpoint adı | |
| api_visibility="public" # Dışarıdan POST kabul eder | |
| ) | |
| demo.launch() |