Update app.py
Browse files
app.py
CHANGED
|
@@ -54,7 +54,7 @@ except Exception as e:
|
|
| 54 |
_initial_logs.append(f"❌ LLM yüklenirken kritik hata: {e}")
|
| 55 |
gen_pipe = None
|
| 56 |
IS_LLM_ENABLED = False
|
| 57 |
-
_initial_logs.append("⚠️ LLM
|
| 58 |
|
| 59 |
_initial_logs.append("✅ Modeller Hazır!")
|
| 60 |
|
|
@@ -65,7 +65,7 @@ _initial_logs.append("✅ Modeller Hazır!")
|
|
| 65 |
# ... (Wikipedia Fonksiyonu)
|
| 66 |
wikipedia.set_lang("tr")
|
| 67 |
def get_wiki_summary(term):
|
| 68 |
-
"""Wikipedia'dan bir terim için özet bilgi
|
| 69 |
try:
|
| 70 |
page = wikipedia.page(term, auto_suggest=True, redirect=True)
|
| 71 |
return wikipedia.summary(page.title, sentences=3, auto_suggest=False)
|
|
@@ -76,12 +76,12 @@ def get_wiki_summary(term):
|
|
| 76 |
Exception):
|
| 77 |
return None
|
| 78 |
|
| 79 |
-
# --- LLM ile Etiket
|
| 80 |
def refine_label_with_llm(entity_text, wiki_context, custom_label_definitions):
|
| 81 |
-
"""LLM kullanarak MISC etiketini özel etiketlerden biriyle
|
| 82 |
|
| 83 |
if not IS_LLM_ENABLED or gen_pipe is None:
|
| 84 |
-
return "MISC", "LLM devre dışı olduğu için
|
| 85 |
|
| 86 |
refinable_labels = {k: v for k, v in custom_label_definitions.items() if k not in ["PER", "LOC", "ORG", "MISC"]}
|
| 87 |
label_definitions_str = "\n".join(
|
|
@@ -304,14 +304,28 @@ def process_ner_request(text, progress=gr.Progress()):
|
|
| 304 |
|
| 305 |
if final_results:
|
| 306 |
color_map = {
|
| 307 |
-
"PER": "background-color: #f8c291;",
|
|
|
|
|
|
|
| 308 |
"MISC": "background-color: #fef08a; font-weight: bold;",
|
| 309 |
-
"DATE": "background-color: #e5ccff;",
|
| 310 |
-
"
|
| 311 |
-
"
|
| 312 |
-
"
|
| 313 |
-
"
|
| 314 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
"CYBER": "background-color: #dbeafe;"
|
| 316 |
}
|
| 317 |
|
|
@@ -372,9 +386,9 @@ def process_ner_request(text, progress=gr.Progress()):
|
|
| 372 |
iface = gr.Interface(
|
| 373 |
fn=process_ner_request,
|
| 374 |
inputs=gr.Textbox(lines=5, placeholder="Metin giriniz...", label="Giriş Metni"),
|
| 375 |
-
outputs=[gr.HTML(label="İşlem Logları"), gr.HTML(label="
|
| 376 |
-
title="
|
| 377 |
-
description="
|
| 378 |
examples=[
|
| 379 |
["Milli Eğitim Bakanlığı'na bağlı Lise Birimleri, 2024 Türkiye Kupası etkinliğine katılacak ve %15 indirim uygulayacak."],
|
| 380 |
["General Vural, Türkçe dilini kullanan Türk askerlerini, https://example.com üzerinden uyardı. 'Hürriyet Kasidesi' eserini okudu."],
|
|
|
|
| 54 |
_initial_logs.append(f"❌ LLM yüklenirken kritik hata: {e}")
|
| 55 |
gen_pipe = None
|
| 56 |
IS_LLM_ENABLED = False
|
| 57 |
+
_initial_logs.append("⚠️ LLM devre dışı bırakıldı. Uygulamayı sadece Standart NER yapacaktır.")
|
| 58 |
|
| 59 |
_initial_logs.append("✅ Modeller Hazır!")
|
| 60 |
|
|
|
|
| 65 |
# ... (Wikipedia Fonksiyonu)
|
| 66 |
wikipedia.set_lang("tr")
|
| 67 |
def get_wiki_summary(term):
|
| 68 |
+
"""Wikipedia'dan bir terim için özet bilgi çekme."""
|
| 69 |
try:
|
| 70 |
page = wikipedia.page(term, auto_suggest=True, redirect=True)
|
| 71 |
return wikipedia.summary(page.title, sentences=3, auto_suggest=False)
|
|
|
|
| 76 |
Exception):
|
| 77 |
return None
|
| 78 |
|
| 79 |
+
# --- LLM ile Etiket Güncelleme Fonksiyonu ---
|
| 80 |
def refine_label_with_llm(entity_text, wiki_context, custom_label_definitions):
|
| 81 |
+
"""LLM kullanarak MISC etiketini özel etiketlerden biriyle değiştirme."""
|
| 82 |
|
| 83 |
if not IS_LLM_ENABLED or gen_pipe is None:
|
| 84 |
+
return "MISC", "LLM devre dışı olduğu için güncellenemedi."
|
| 85 |
|
| 86 |
refinable_labels = {k: v for k, v in custom_label_definitions.items() if k not in ["PER", "LOC", "ORG", "MISC"]}
|
| 87 |
label_definitions_str = "\n".join(
|
|
|
|
| 304 |
|
| 305 |
if final_results:
|
| 306 |
color_map = {
|
| 307 |
+
"PER": "background-color: #f8c291;",
|
| 308 |
+
"ORG": "background-color: #b3c99f;",
|
| 309 |
+
"LOC": "background-color: #a2c4c9;",
|
| 310 |
"MISC": "background-color: #fef08a; font-weight: bold;",
|
| 311 |
+
"DATE": "background-color: #e5ccff;",
|
| 312 |
+
"TIME": "background-color: #d1d5db;",
|
| 313 |
+
"MONEY": "background-color: #fcd34d;",
|
| 314 |
+
"QUANTITY": "background-color: #bfdbfe;",
|
| 315 |
+
"PERCENT": "background-color: #99f6e4;",
|
| 316 |
+
"NORP": "background-color: #fbcfe8;",
|
| 317 |
+
"LAW": "background-color: #f0abfc;",
|
| 318 |
+
"EVENT": "background-color: #a7f3d0;",
|
| 319 |
+
"BOOK": "background-color: #ffedd5;",
|
| 320 |
+
"MOVIE": "background-color: #c7d2fe;",
|
| 321 |
+
"SONG": "background-color: #e9d5ff;",
|
| 322 |
+
"ART": "background-color: #bae6fd;",
|
| 323 |
+
"AWARD": "background-color: #fee2e2;",
|
| 324 |
+
"PRODUCT": "background-color: #ffc999;",
|
| 325 |
+
"SOFTWARE": "background-color: #d1fae5;",
|
| 326 |
+
"ORG_SUB": "background-color: #ccfbf1;",
|
| 327 |
+
"LANGUAGE": "background-color: #fef9c3;",
|
| 328 |
+
"TITLE": "background-color: #fecaca;",
|
| 329 |
"CYBER": "background-color: #dbeafe;"
|
| 330 |
}
|
| 331 |
|
|
|
|
| 386 |
iface = gr.Interface(
|
| 387 |
fn=process_ner_request,
|
| 388 |
inputs=gr.Textbox(lines=5, placeholder="Metin giriniz...", label="Giriş Metni"),
|
| 389 |
+
outputs=[gr.HTML(label="İşlem Logları"), gr.HTML(label="Güncellenmiş NER Sonuçları")],
|
| 390 |
+
title="NER-Project v1",
|
| 391 |
+
description="1to20forMISC",
|
| 392 |
examples=[
|
| 393 |
["Milli Eğitim Bakanlığı'na bağlı Lise Birimleri, 2024 Türkiye Kupası etkinliğine katılacak ve %15 indirim uygulayacak."],
|
| 394 |
["General Vural, Türkçe dilini kullanan Türk askerlerini, https://example.com üzerinden uyardı. 'Hürriyet Kasidesi' eserini okudu."],
|