apak commited on
Commit
a12a7ee
·
verified ·
1 Parent(s): 69865a9

Update ui_modules.py

Browse files
Files changed (1) hide show
  1. ui_modules.py +79 -38
ui_modules.py CHANGED
@@ -1,48 +1,89 @@
1
  import gradio as gr
2
 
3
- def create_ui_layout():
4
- # CSS'e ikon ve kart tasarımları eklendi
5
- custom_css = """
6
- .entity-card { border: 1px solid #e0e0e0; padding: 15px; border-radius: 10px; margin-bottom: 15px; background: #ffffff; box-shadow: 2px 2px 5px rgba(0,0,0,0.05); }
7
- .wiki-section { color: #0056b3; background: #f0f7ff; padding: 5px; border-radius: 5px; margin: 5px 0; }
8
- .llm-section { color: #155724; background: #f4fff3; padding: 5px; border-radius: 5px; margin: 5px 0; }
9
  """
 
 
 
10
 
11
- with gr.Blocks(title="RAG-NER Uzman Sistemi", css=custom_css) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  gr.Markdown("# 🚀 RAG-NER Uzman Karar Destek Sistemi")
 
13
 
14
  with gr.Tab("Metin Analizi"):
15
- input_text = gr.Textbox(label="Analiz Edilecek Metin", lines=3, placeholder="Metni buraya girin...")
16
-
17
- # Eksik olan hazır örnekler burada tanımlandı
18
- gr.Examples(
19
- examples=[
20
- ["Antalya Altın Portakal ödülünü Vizontele filmi aldı."],
21
- ["Nuri Bilge Ceylan, Kış Uykusu filmiyle Cannes Film Festivali'nde ödül kazandı."],
22
- ["Amerikalı yazar George Orwell'in 1984 romanı, Apple'ın Macintosh reklamına ilham verdi."],
23
- ["Android işletim sistemli bir telefon aldım, içinde Python yüklüydü."]
24
- ],
25
- inputs=input_text,
26
- label="Hazır Senaryolar"
27
- )
28
-
29
  with gr.Row():
30
- log_output = gr.HTML(label="Sistem Akış Günlüğü")
31
- table_output = gr.Dataframe(headers=["Varlık", "İlk", "Nihai", "Kaynak"], datatype="markdown", wrap=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- submit_btn = gr.Button("Analiz Et", variant="primary")
34
 
35
- return demo, input_text, log_output, table_output, submit_btn
36
-
37
- def format_entity_log(word, wiki, reasoning, label):
38
- # İkonlar ve hiyerarşik yapı
39
- return f"""
40
- <div class='entity-card'>
41
- <div style='font-size: 1.2em; font-weight: bold; color: #333;'>🔍 Tespit Edilen: {word}</div>
42
- <div class='wiki-section'>🌐 <b>Wikipedia:</b> {wiki}</div>
43
- <div class='llm-section'>🧠 <b>LLM CoT Analizi:</b> {reasoning}</div>
44
- <div style='margin-top: 10px; border-top: 1px dashed #ccc; pt: 5px;'>
45
- 🎯 <b>Yeni Etiket:</b> <span style='color: #e67e22; font-size: 1.1em;'>{label}</span>
46
- </div>
47
- </div>
48
- """
 
1
  import gradio as gr
2
 
3
+ def format_entity_log(word, wiki, reasoning, new_label):
4
+ """
5
+ LLM'den gelen analiz sonuçlarını şık bir HTML kart yapısına dönüştürür.
 
 
 
6
  """
7
+ # Adımları parçalara ayırarak daha okunaklı hale getirelim
8
+ steps = reasoning.split('|')
9
+ steps_html = ""
10
 
11
+ # Her bir adımı ikonlu ve temiz bir satır olarak biçimlendir
12
+ for step in steps:
13
+ if step.strip():
14
+ steps_html += f"<div style='margin-bottom: 5px; font-size: 0.9em; color: #34495e;'>• {step.strip()}</div>"
15
+
16
+ return f"""
17
+ <div style="border: 1px solid #e0e0e0; border-radius: 10px; padding: 15px; margin-bottom: 15px; background-color: #ffffff; box-shadow: 2px 2px 5px rgba(0,0,0,0.05);">
18
+ <div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #3498db; padding-bottom: 8px; margin-bottom: 10px;">
19
+ <span style="font-weight: bold; font-size: 1.1em; color: #2c3e50;">🔍 Tespit Edilen: {word}</span>
20
+ <span style="background-color: #3498db; color: white; padding: 2px 10px; border-radius: 15px; font-size: 0.85em;">{new_label}</span>
21
+ </div>
22
+
23
+ <div style="background-color: #f8f9fa; border-left: 4px solid #9b59b6; padding: 8px; margin-bottom: 10px; border-radius: 4px;">
24
+ <small style="color: #8e44ad; font-weight: bold;">🌐 Wikipedia Özeti:</small>
25
+ <p style="margin: 5px 0 0 0; font-size: 0.9em; color: #2c3e50;">{wiki}</p>
26
+ </div>
27
+
28
+ <div style="background-color: #f0fdf4; border-left: 4px solid #27ae60; padding: 8px; border-radius: 4px;">
29
+ <small style="color: #218838; font-weight: bold;">🧠 LLM Karar Mekanizması (CoT):</small>
30
+ <div style="margin-top: 5px;">
31
+ {steps_html}
32
+ </div>
33
+ </div>
34
+
35
+ <div style="margin-top: 10px; text-align: right;">
36
+ <span style="font-size: 0.8em; color: #7f8c8d;">🎯 Yeni Etiket: <b style="color: #e67e22;">{new_label}</b></span>
37
+ </div>
38
+ </div>
39
+ """
40
+
41
+ def create_ui_layout():
42
+ """
43
+ Gradio arayüzünün iskeletini oluşturur.
44
+ """
45
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="orange", secondary_hue="blue")) as demo:
46
  gr.Markdown("# 🚀 RAG-NER Uzman Karar Destek Sistemi")
47
+ gr.Markdown("MISC varlıkları Wikipedia ve LLM muhakemesi ile otomatik olarak yeniden etiketler.")
48
 
49
  with gr.Tab("Metin Analizi"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  with gr.Row():
51
+ with gr.Column(scale=2):
52
+ input_text = gr.Textbox(
53
+ label="Analiz Edilecek Metin",
54
+ placeholder="Örn: Antalya Altın Portakal ödülünü Vizontele filmi aldı.",
55
+ lines=4
56
+ )
57
+
58
+ # Hazır senaryolar (Kullanıcı için kolaylık)
59
+ gr.Examples(
60
+ examples=[
61
+ ["Antalya Altın Portakal ödülünü Vizontele filmi aldı."],
62
+ ["Nuri Bilge Ceylan, Kış Uykusu filmiyle Cannes Film Festivali'nde ödül kazandı."],
63
+ ["Amerikalı yazar George Orwell'in 1984 romanı, Apple'ın Macintosh reklamına ilham verdi."],
64
+ ["Android işletim sistemli bir telefon aldım, içinde Python yüklüydü."]
65
+ ],
66
+ inputs=input_text,
67
+ label="Hazır Senaryolar"
68
+ )
69
+
70
+ analyze_btn = gr.Button("Analiz Et", variant="primary", size="lg")
71
+
72
+ with gr.Column(scale=1):
73
+ # Sağ panelde hızlı sonuç tablosu
74
+ output_table = gr.Dataframe(
75
+ headers=["Varlık", "İlk", "Nihai", "Kaynak"],
76
+ datatype=["str", "str", "html", "str"],
77
+ label="Analiz Özeti"
78
+ )
79
 
80
+ gr.Divider()
81
 
82
+ with gr.Row():
83
+ # Alt panelde detaylı reasoning logları
84
+ output_logs = gr.HTML(
85
+ label="Detaylı Muhakeme Kartları",
86
+ value="<p style='text-align:center; color:gray;'>Analiz sonuçları burada kartlar halinde görünecektir.</p>"
87
+ )
88
+
89
+ return demo, input_text, output_logs, output_table, analyze_btn