Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -75,16 +75,30 @@ Cevap: [Sadece ETIKET_ADI]"""
|
|
| 75 |
response_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
|
| 76 |
full_output = tokenizer.batch_decode(response_ids, skip_special_tokens=True)[0].strip()
|
| 77 |
|
| 78 |
-
|
| 79 |
final_label = "MISC"
|
| 80 |
valid_keys = list(custom_label_definitions.keys())
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
if match:
|
| 84 |
-
extracted = match.group(1).upper()
|
| 85 |
if extracted in valid_keys:
|
| 86 |
final_label = extracted
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
return final_label, full_output
|
| 89 |
except Exception as e:
|
| 90 |
return "MISC", f"Hata: {str(e)}"
|
|
|
|
| 75 |
response_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
|
| 76 |
full_output = tokenizer.batch_decode(response_ids, skip_special_tokens=True)[0].strip()
|
| 77 |
|
| 78 |
+
# Optimize Edilmiş Etiket Ayıklama
|
| 79 |
final_label = "MISC"
|
| 80 |
valid_keys = list(custom_label_definitions.keys())
|
| 81 |
+
|
| 82 |
+
# Regex Açıklaması:
|
| 83 |
+
# Cevap kelimesinden sonra gelebilecek yıldız(*), iki nokta(:) ve boşlukları(\s) kapsar.
|
| 84 |
+
# Yakalanan grup ([A-Z_]+) sadece büyük harf ve alt tire içerir.
|
| 85 |
+
match = re.search(r"Cevap[:\s\*]+([A-Z_]+)", full_output, re.IGNORECASE)
|
| 86 |
|
| 87 |
if match:
|
| 88 |
+
extracted = match.group(1).upper().strip()
|
| 89 |
if extracted in valid_keys:
|
| 90 |
final_label = extracted
|
| 91 |
|
| 92 |
+
# FALLBACK: Eğer yukarıdaki regex yakalayamazsa (Model 'Cevap:' demeyi unutursa)
|
| 93 |
+
if final_label == "MISC":
|
| 94 |
+
# Metnin en sonuna odaklanarak geçerli etiketlerden birini ara
|
| 95 |
+
upper_output = full_output.upper()
|
| 96 |
+
for key in valid_keys:
|
| 97 |
+
if key in upper_output:
|
| 98 |
+
final_label = key
|
| 99 |
+
# Not: Birden fazla etiket geçerse sonuncuyu/ilkini alma tercihi yapılabilir.
|
| 100 |
+
break
|
| 101 |
+
|
| 102 |
return final_label, full_output
|
| 103 |
except Exception as e:
|
| 104 |
return "MISC", f"Hata: {str(e)}"
|