Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
app_py_content = '''
|
| 2 |
import torch
|
| 3 |
import wikipedia
|
| 4 |
from transformers import pipeline
|
|
@@ -28,7 +27,8 @@ gen_pipe = pipeline(
|
|
| 28 |
model_kwargs=llm_model_kwargs,
|
| 29 |
device_map=llm_device_map
|
| 30 |
)
|
| 31 |
-
print("
|
|
|
|
| 32 |
|
| 33 |
# --- Wikipedia Fonksiyonu ---
|
| 34 |
wikipedia.set_lang("tr")
|
|
@@ -43,7 +43,8 @@ def get_wiki_summary(term):
|
|
| 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 = "
|
|
|
|
| 47 |
[f"- {k}: {v}" for k, v in custom_label_definitions.items()]
|
| 48 |
)
|
| 49 |
|
|
@@ -60,7 +61,7 @@ SONUÇ: MOVIE
|
|
| 60 |
|
| 61 |
ÖRNEK 3 (AWARD İÇİN):
|
| 62 |
VARLIK: Altın Ayı
|
| 63 |
-
BAĞLAM: Berlin
|
| 64 |
SONUÇ: AWARD
|
| 65 |
|
| 66 |
ÖRNEK 4 (SOFTWARE İÇİN):
|
|
@@ -124,7 +125,8 @@ Gerekçe:
|
|
| 124 |
|
| 125 |
final_label = "MISC"
|
| 126 |
try:
|
| 127 |
-
cevap_satiri = [line for line in full_output.split('
|
|
|
|
| 128 |
raw_label = cevap_satiri.split('Cevap:')[-1].strip().upper()
|
| 129 |
|
| 130 |
valid_labels = list(custom_label_definitions.keys()) + ["UNKNOWN"]
|
|
@@ -182,21 +184,34 @@ def process_ner_request(text):
|
|
| 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;'
|
| 186 |
-
|
| 187 |
-
formatted_output += "
|
| 188 |
-
|
| 189 |
-
formatted_output += " <th style='padding: 8px; text-align: left; border: 1px solid #ddd;'>
|
| 190 |
-
|
| 191 |
-
formatted_output += "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
for item in results:
|
| 194 |
-
formatted_output += " <tr style='border: 1px solid #ddd;'
|
| 195 |
-
|
| 196 |
-
formatted_output += f" <td style='padding: 8px; text-align: left; border: 1px solid #ddd;'>{item['
|
| 197 |
-
|
| 198 |
-
formatted_output += f" <td style='padding: 8px; text-align: left; border: 1px solid #ddd;'>{item['
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 200 |
formatted_output += "</table>"
|
| 201 |
return formatted_output
|
| 202 |
|
|
@@ -211,7 +226,4 @@ iface = gr.Interface(
|
|
| 211 |
|
| 212 |
# --- Gradio Uygulamasını Başlat ---
|
| 213 |
if __name__ == "__main__":
|
| 214 |
-
iface.launch(share=True)
|
| 215 |
-
'''
|
| 216 |
-
|
| 217 |
-
print(app_py_content)
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import wikipedia
|
| 3 |
from transformers import pipeline
|
|
|
|
| 27 |
model_kwargs=llm_model_kwargs,
|
| 28 |
device_map=llm_device_map
|
| 29 |
)
|
| 30 |
+
print("
|
| 31 |
+
✅ 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 = "
|
| 47 |
+
".join(
|
| 48 |
[f"- {k}: {v}" for k, v in custom_label_definitions.items()]
|
| 49 |
)
|
| 50 |
|
|
|
|
| 61 |
|
| 62 |
ÖRNEK 3 (AWARD İÇİN):
|
| 63 |
VARLIK: Altın Ayı
|
| 64 |
+
BAĞLAM: Berlin Uluslararası Film Festivali'nde en iyi film için verilen en yüksek ödüldür. (AWARD tanımı ile eşleşir.)
|
| 65 |
SONUÇ: AWARD
|
| 66 |
|
| 67 |
ÖRNEK 4 (SOFTWARE İÇİN):
|
|
|
|
| 125 |
|
| 126 |
final_label = "MISC"
|
| 127 |
try:
|
| 128 |
+
cevap_satiri = [line for line in full_output.split('
|
| 129 |
+
') if 'Cevap:' in line][-1]
|
| 130 |
raw_label = cevap_satiri.split('Cevap:')[-1].strip().upper()
|
| 131 |
|
| 132 |
valid_labels = list(custom_label_definitions.keys()) + ["UNKNOWN"]
|
|
|
|
| 184 |
results = advanced_ner_pipeline(text, custom_label_definitions)
|
| 185 |
|
| 186 |
# Sonuçları daha okunaklı bir formatta string olarak döndür
|
| 187 |
+
formatted_output = """<table style='width:100%; border-collapse: collapse;'>
|
| 188 |
+
"""
|
| 189 |
+
formatted_output += " <tr style='background-color: #f2f2f2; border: 1px solid #ddd;'>
|
| 190 |
+
"
|
| 191 |
+
formatted_output += " <th style='padding: 8px; text-align: left; border: 1px solid #ddd;'>VARLIK</th>
|
| 192 |
+
"
|
| 193 |
+
formatted_output += " <th style='padding: 8px; text-align: left; border: 1px solid #ddd;'>İLK ETİKET</th>
|
| 194 |
+
"
|
| 195 |
+
formatted_output += " <th style='padding: 8px; text-align: left; border: 1px solid #ddd;'>RAG SONRASI</th>
|
| 196 |
+
"
|
| 197 |
+
formatted_output += " <th style='padding: 8px; text-align: left; border: 1px solid #ddd;'>KAYNAK</th>
|
| 198 |
+
"
|
| 199 |
+
formatted_output += " </tr>
|
| 200 |
+
"
|
| 201 |
|
| 202 |
for item in results:
|
| 203 |
+
formatted_output += " <tr style='border: 1px solid #ddd;'>
|
| 204 |
+
"
|
| 205 |
+
formatted_output += f" <td style='padding: 8px; text-align: left; border: 1px solid #ddd;'>{item['entity']}</td>
|
| 206 |
+
"
|
| 207 |
+
formatted_output += f" <td style='padding: 8px; text-align: left; border: 1px solid #ddd;'>{item['initial_label']}</td>
|
| 208 |
+
"
|
| 209 |
+
formatted_output += f" <td style='padding: 8px; text-align: left; border: 1px solid #ddd;'>{item['final_label']}</td>
|
| 210 |
+
"
|
| 211 |
+
formatted_output += f" <td style='padding: 8px; text-align: left; border: 1px solid #ddd;'>{item['source']}</td>
|
| 212 |
+
"
|
| 213 |
+
formatted_output += " </tr>
|
| 214 |
+
"
|
| 215 |
formatted_output += "</table>"
|
| 216 |
return formatted_output
|
| 217 |
|
|
|
|
| 226 |
|
| 227 |
# --- Gradio Uygulamasını Başlat ---
|
| 228 |
if __name__ == "__main__":
|
| 229 |
+
iface.launch(share=True)
|
|
|
|
|
|
|
|
|