cagrigungor commited on
Commit
a397d6d
·
verified ·
1 Parent(s): 440d996

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -27
app.py CHANGED
@@ -1,35 +1,22 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- def respond(
5
- message,
6
- history: list[dict[str, str]],
7
- system_message,
8
- hf_token: gr.OAuthToken,
9
- ):
10
- """
11
- Türkçe toksisite sınıflandırıcısı (cagrigungor/turkishtoxic-classifier)
12
- Bu fonksiyon, kullanıcının yazdığı mesajı model API üzerinden sınıflandırır.
13
- """
14
-
15
- # Hugging Face Inference API client
16
- client = InferenceClient(model="cagrigungor/turkishtoxic-classifier", token=hf_token.token)
17
-
18
- # Modeli çağır
19
- result = client.text_classification(message)
20
  label = result[0]["label"]
21
  score = round(result[0]["score"], 3)
22
 
23
- # Cevap formatı
24
  if label == "toxic":
25
- answer = f"⚠️ **Toksik içerik tespit edildi.**\n\nSkor: {score}"
26
  else:
27
  answer = f"✅ **Temiz içerik (notoxic)**\n\nSkor: {score}"
28
 
29
  yield answer
30
 
31
 
32
- # --- Gradio Chat Interface ---
33
  chatbot = gr.ChatInterface(
34
  respond,
35
  type="messages",
@@ -40,19 +27,15 @@ chatbot = gr.ChatInterface(
40
  ),
41
  ],
42
  title="🇹🇷 Türkçe Toksisite Chatbot",
43
- description="Bu chatbot, kullanıcı mesajlarını analiz ederek toksik (küfür/hakaret içeren) olup olmadığını belirtir.\n\nModel: **cagrigungor/turkishtoxic-classifier**",
44
  examples=[
45
  ["Bugün hava çok güzel."],
46
  ["Sen tam bir salaksın!"],
47
- ["Böyle konuşmalar hoş değil."],
48
  ],
49
  )
50
 
51
  with gr.Blocks() as demo:
52
- with gr.Sidebar():
53
- gr.LoginButton()
54
- gr.Markdown("## 🔐 Hugging Face hesabınızla giriş yapın")
55
- gr.Markdown("Giriş yaptıktan sonra model otomatik olarak API erişimiyle çalışır (CPU yeterlidir).")
56
  chatbot.render()
57
 
58
  if __name__ == "__main__":
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Modeli doğrudan transformers üzerinden yükle
5
+ clf = pipeline("text-classification", model="cagrigungor/turkishtoxic-classifier")
6
+
7
+ def respond(message, history: list[dict[str, str]], system_message):
8
+ result = clf(message)
 
 
 
 
 
 
 
 
 
 
 
9
  label = result[0]["label"]
10
  score = round(result[0]["score"], 3)
11
 
 
12
  if label == "toxic":
13
+ answer = f"⚠️ **Toksik içerik tespit edildi!**\n\nSkor: {score}"
14
  else:
15
  answer = f"✅ **Temiz içerik (notoxic)**\n\nSkor: {score}"
16
 
17
  yield answer
18
 
19
 
 
20
  chatbot = gr.ChatInterface(
21
  respond,
22
  type="messages",
 
27
  ),
28
  ],
29
  title="🇹🇷 Türkçe Toksisite Chatbot",
30
+ description="Bu chatbot, yazdığınız Türkçe metnin toksik (küfür/hakaret) içerip içermediğini tahmin eder.\n\nModel: **cagrigungor/turkishtoxic-classifier**",
31
  examples=[
32
  ["Bugün hava çok güzel."],
33
  ["Sen tam bir salaksın!"],
34
+ ["Bu fikir hiç de kötü değil."],
35
  ],
36
  )
37
 
38
  with gr.Blocks() as demo:
 
 
 
 
39
  chatbot.render()
40
 
41
  if __name__ == "__main__":