Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import wikipedia
|
| 3 |
from transformers import pipeline
|
|
@@ -27,7 +28,7 @@ gen_pipe = pipeline(
|
|
| 27 |
model_kwargs=llm_model_kwargs,
|
| 28 |
device_map=llm_device_map
|
| 29 |
)
|
| 30 |
-
print("
|
| 31 |
|
| 32 |
# --- Wikipedia Fonksiyonu ---
|
| 33 |
wikipedia.set_lang("tr")
|
|
@@ -42,7 +43,7 @@ def get_wiki_summary(term):
|
|
| 42 |
# --- LLM ile Etiket Rafine Etme Fonksiyonu ---
|
| 43 |
def refine_label_with_llm(entity_text, wiki_context, custom_label_definitions):
|
| 44 |
labels_str = ", ".join(custom_label_definitions.keys())
|
| 45 |
-
label_definitions_str = "
|
| 46 |
[f"- {k}: {v}" for k, v in custom_label_definitions.items()]
|
| 47 |
)
|
| 48 |
|
|
@@ -123,7 +124,7 @@ Gerekçe:
|
|
| 123 |
|
| 124 |
final_label = "MISC"
|
| 125 |
try:
|
| 126 |
-
cevap_satiri = [line for line in full_output.split('
|
| 127 |
raw_label = cevap_satiri.split('Cevap:')[-1].strip().upper()
|
| 128 |
|
| 129 |
valid_labels = list(custom_label_definitions.keys()) + ["UNKNOWN"]
|
|
@@ -181,34 +182,21 @@ def process_ner_request(text):
|
|
| 181 |
results = advanced_ner_pipeline(text, custom_label_definitions)
|
| 182 |
|
| 183 |
# Sonuçları daha okunaklı bir formatta string olarak döndür
|
| 184 |
-
formatted_output = """<table style='width:100%; border-collapse: collapse;'
|
| 185 |
-
""
|
| 186 |
-
formatted_output += "
|
| 187 |
-
"
|
| 188 |
-
formatted_output += " <th style='padding: 8px; text-align: left; border: 1px solid #ddd;'>
|
| 189 |
-
"
|
| 190 |
-
formatted_output += "
|
| 191 |
-
"
|
| 192 |
-
formatted_output += " <th style='padding: 8px; text-align: left; border: 1px solid #ddd;'>RAG SONRASI</th>
|
| 193 |
-
"
|
| 194 |
-
formatted_output += " <th style='padding: 8px; text-align: left; border: 1px solid #ddd;'>KAYNAK</th>
|
| 195 |
-
"
|
| 196 |
-
formatted_output += " </tr>
|
| 197 |
-
"
|
| 198 |
|
| 199 |
for item in results:
|
| 200 |
-
formatted_output += " <tr style='border: 1px solid #ddd;'
|
| 201 |
-
"
|
| 202 |
-
formatted_output += f" <td style='padding: 8px; text-align: left; border: 1px solid #ddd;'>{item['
|
| 203 |
-
"
|
| 204 |
-
formatted_output += f" <td style='padding: 8px; text-align: left; border: 1px solid #ddd;'>{item['
|
| 205 |
-
"
|
| 206 |
-
formatted_output += f" <td style='padding: 8px; text-align: left; border: 1px solid #ddd;'>{item['final_label']}</td>
|
| 207 |
-
"
|
| 208 |
-
formatted_output += f" <td style='padding: 8px; text-align: left; border: 1px solid #ddd;'>{item['source']}</td>
|
| 209 |
-
"
|
| 210 |
-
formatted_output += " </tr>
|
| 211 |
-
"
|
| 212 |
formatted_output += "</table>"
|
| 213 |
return formatted_output
|
| 214 |
|
|
@@ -224,3 +212,4 @@ iface = gr.Interface(
|
|
| 224 |
# --- Gradio Uygulamasını Başlat ---
|
| 225 |
if __name__ == "__main__":
|
| 226 |
iface.launch(share=True)
|
|
|
|
|
|
| 1 |
+
|
| 2 |
import torch
|
| 3 |
import wikipedia
|
| 4 |
from transformers import pipeline
|
|
|
|
| 28 |
model_kwargs=llm_model_kwargs,
|
| 29 |
device_map=llm_device_map
|
| 30 |
)
|
| 31 |
+
print("\n✅ Modeller Hazır!")
|
| 32 |
|
| 33 |
# --- Wikipedia Fonksiyonu ---
|
| 34 |
wikipedia.set_lang("tr")
|
|
|
|
| 43 |
# --- LLM ile Etiket Rafine Etme Fonksiyonu ---
|
| 44 |
def refine_label_with_llm(entity_text, wiki_context, custom_label_definitions):
|
| 45 |
labels_str = ", ".join(custom_label_definitions.keys())
|
| 46 |
+
label_definitions_str = "\n".join(
|
| 47 |
[f"- {k}: {v}" for k, v in custom_label_definitions.items()]
|
| 48 |
)
|
| 49 |
|
|
|
|
| 124 |
|
| 125 |
final_label = "MISC"
|
| 126 |
try:
|
| 127 |
+
cevap_satiri = [line for line in full_output.split('\n') if 'Cevap:' in line][-1]
|
| 128 |
raw_label = cevap_satiri.split('Cevap:')[-1].strip().upper()
|
| 129 |
|
| 130 |
valid_labels = list(custom_label_definitions.keys()) + ["UNKNOWN"]
|
|
|
|
| 182 |
results = advanced_ner_pipeline(text, custom_label_definitions)
|
| 183 |
|
| 184 |
# Sonuçları daha okunaklı bir formatta string olarak döndür
|
| 185 |
+
formatted_output = """<table style='width:100%; border-collapse: collapse;'>\n"""
|
| 186 |
+
formatted_output += " <tr style='background-color: #f2f2f2; border: 1px solid #ddd;'>\n"
|
| 187 |
+
formatted_output += " <th style='padding: 8px; text-align: left; border: 1px solid #ddd;'>VARLIK</th>\n"
|
| 188 |
+
formatted_output += " <th style='padding: 8px; text-align: left; border: 1px solid #ddd;'>İLK ETİKET</th>\n"
|
| 189 |
+
formatted_output += " <th style='padding: 8px; text-align: left; border: 1px solid #ddd;'>RAG SONRASI</th>\n"
|
| 190 |
+
formatted_output += " <th style='padding: 8px; text-align: left; border: 1px solid #ddd;'>KAYNAK</th>\n"
|
| 191 |
+
formatted_output += " </tr>\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
for item in results:
|
| 194 |
+
formatted_output += " <tr style='border: 1px solid #ddd;'>\n"
|
| 195 |
+
formatted_output += f" <td style='padding: 8px; text-align: left; border: 1px solid #ddd;'>{item['entity']}</td>\n"
|
| 196 |
+
formatted_output += f" <td style='padding: 8px; text-align: left; border: 1px solid #ddd;'>{item['initial_label']}</td>\n"
|
| 197 |
+
formatted_output += f" <td style='padding: 8px; text-align: left; border: 1px solid #ddd;'>{item['final_label']}</td>\n"
|
| 198 |
+
formatted_output += f" <td style='padding: 8px; text-align: left; border: 1px solid #ddd;'>{item['source']}</td>\n"
|
| 199 |
+
formatted_output += " </tr>\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
formatted_output += "</table>"
|
| 201 |
return formatted_output
|
| 202 |
|
|
|
|
| 212 |
# --- Gradio Uygulamasını Başlat ---
|
| 213 |
if __name__ == "__main__":
|
| 214 |
iface.launch(share=True)
|
| 215 |
+
|