File size: 1,772 Bytes
d9e276a
 
614a658
d9e276a
 
c6921bf
614a658
 
d9e276a
fef8d11
 
27b7ff0
fef8d11
27b7ff0
fef8d11
c6921bf
614a658
d9e276a
 
fef8d11
27b7ff0
d9e276a
c6921bf
 
 
27b7ff0
614a658
 
27b7ff0
 
614a658
27b7ff0
69865a9
c6921bf
d9e276a
fef8d11
614a658
27b7ff0
d9e276a
 
c6921bf
 
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
40
41
42
import gradio as gr
from ner_logic import ner_pipe, get_wiki_summary, refine_labels_batch
from ui_modules import create_ui_layout, format_entity_log

def process_ner(text):
    yield "Analiz Başlatıldı...", []
    final_results = []
    misc_buffer = []
    
    ents = ner_pipe(text)
    for ent in ents:
        w, l = ent['word'].strip(), ent['entity_group']
        if l in ["PER", "ORG", "LOC"]:
            final_results.append({"Varlık": w, "İlk": l, "Nihai": l, "Kaynak": "Model"})
        elif l == "MISC":
            wiki = get_wiki_summary(w) or "Bilgi yok."
            misc_buffer.append({"word": w, "wiki": wiki})

    if misc_buffer:
        responses = refine_labels_batch(misc_buffer, text)
        logs = []
        for item in misc_buffer:
            # Esnek isim eşleşmesi ile KeyError riskini azaltıyoruz
            res = next((r for r in responses if item['word'].lower() in r.get('varlik', '').lower()), {})
            
            reasoning = res.get('reasoning', 'Reasoning oluşturulamadı.')
            new_label = res.get('karar', 'MISC')
            
            logs.append(format_entity_log(item['word'], item['wiki'], reasoning, new_label))
            final_results.append({"Varlık": item['word'], "İlk": "MISC", "Nihai": new_label, "Kaynak": "RAG+LLM"})
            
            yield "".join(logs), [[r["Varlık"], r["İlk"], r["Nihai"], r["Kaynak"]] for r in final_results]
    else:
        yield "Tamamlandı.", [[r["Varlık"], r["İlk"], r["Nihai"], r["Kaynak"]] for r in final_results]

demo, inp, log, tbl, btn = create_ui_layout()
with demo:
    btn.click(process_ner, inputs=inp, outputs=[log, tbl])

if __name__ == "__main__":
    # Hugging Face ortamında auth gerekebilir veya kaldırılabilir
    demo.launch()