Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,36 @@
|
|
| 1 |
import os
|
| 2 |
import torch
|
| 3 |
import gradio as gr
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
-
# =========================================================
|
| 8 |
# GOSHAWK INSURANCE AI
|
| 9 |
-
# DistilBERT - Insurance
|
| 10 |
-
# CPU
|
| 11 |
-
# =========================================================
|
| 12 |
|
| 13 |
-
# Model dosyaları bu Space'in içinde olduğu için
|
| 14 |
-
# Hugging Face'e tekrar bağlanmıyoruz.
|
| 15 |
MODEL_PATH = "./"
|
| 16 |
-
|
| 17 |
DEVICE = torch.device("cpu")
|
| 18 |
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
#
|
| 22 |
-
#
|
| 23 |
|
| 24 |
-
print("=
|
| 25 |
print("GOSHAWK INSURANCE AI")
|
| 26 |
print("Model yükleniyor...")
|
| 27 |
-
print("=
|
| 28 |
|
| 29 |
try:
|
|
|
|
| 30 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 31 |
MODEL_PATH,
|
| 32 |
local_files_only=True
|
|
@@ -40,171 +44,375 @@ try:
|
|
| 40 |
model.to(DEVICE)
|
| 41 |
model.eval()
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
print("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
except Exception as e:
|
| 48 |
-
print("MODEL YÜKLEME HATASI:")
|
| 49 |
-
print(str(e))
|
| 50 |
-
raise e
|
| 51 |
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
def predict(text):
|
| 58 |
|
|
|
|
| 59 |
if text is None or not text.strip():
|
|
|
|
| 60 |
return {
|
| 61 |
-
"
|
|
|
|
| 62 |
}
|
| 63 |
|
|
|
|
| 64 |
text = text.strip()
|
| 65 |
|
|
|
|
| 66 |
try:
|
| 67 |
|
| 68 |
-
#
|
|
|
|
|
|
|
|
|
|
| 69 |
inputs = tokenizer(
|
| 70 |
text,
|
| 71 |
return_tensors="pt",
|
| 72 |
truncation=True,
|
| 73 |
padding=True,
|
| 74 |
-
max_length=
|
| 75 |
)
|
| 76 |
|
|
|
|
|
|
|
| 77 |
# CPU
|
|
|
|
|
|
|
| 78 |
inputs = {
|
| 79 |
key: value.to(DEVICE)
|
| 80 |
for key, value in inputs.items()
|
| 81 |
}
|
| 82 |
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
with torch.inference_mode():
|
| 85 |
|
| 86 |
outputs = model(**inputs)
|
| 87 |
|
|
|
|
|
|
|
| 88 |
probabilities = torch.softmax(
|
| 89 |
-
|
| 90 |
dim=-1
|
| 91 |
-
)
|
| 92 |
|
| 93 |
-
# Sonuçları hazırla
|
| 94 |
-
results = {}
|
| 95 |
|
| 96 |
-
|
|
|
|
|
|
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
)
|
| 102 |
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
2
|
| 106 |
)
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
)
|
| 113 |
|
| 114 |
-
confidence = results[best_label]
|
| 115 |
|
| 116 |
-
#
|
|
|
|
|
|
|
|
|
|
| 117 |
sorted_results = dict(
|
| 118 |
sorted(
|
| 119 |
-
|
| 120 |
-
key=lambda
|
| 121 |
reverse=True
|
| 122 |
)
|
| 123 |
)
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
return {
|
|
|
|
| 126 |
"Tahmin": best_label,
|
| 127 |
-
|
| 128 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
label: f"{score:.2f}%"
|
| 130 |
-
for label, score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
}
|
|
|
|
| 132 |
}
|
| 133 |
|
| 134 |
-
|
|
|
|
| 135 |
|
| 136 |
return {
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
}
|
| 139 |
|
| 140 |
|
| 141 |
-
#
|
| 142 |
-
#
|
| 143 |
-
#
|
| 144 |
|
| 145 |
examples = [
|
|
|
|
| 146 |
[
|
| 147 |
"Araç kazası sonucunda ön tampon ve far hasar gördü."
|
| 148 |
],
|
|
|
|
| 149 |
[
|
| 150 |
"Sigortalı kasko poliçesi kapsamında hasar başvurusunda bulundu."
|
| 151 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
[
|
| 153 |
-
"
|
| 154 |
],
|
|
|
|
| 155 |
[
|
| 156 |
-
"
|
| 157 |
],
|
|
|
|
| 158 |
[
|
| 159 |
-
"Sigortalının
|
| 160 |
]
|
|
|
|
| 161 |
]
|
| 162 |
|
| 163 |
|
| 164 |
-
#
|
| 165 |
-
#
|
| 166 |
-
#
|
| 167 |
|
| 168 |
-
|
|
|
|
|
|
|
| 169 |
|
| 170 |
-
|
|
|
|
|
|
|
| 171 |
|
| 172 |
-
|
| 173 |
-
label="Sigorta Metni",
|
| 174 |
-
placeholder=(
|
| 175 |
-
"Örneğin: "
|
| 176 |
-
"Araç kazası sonucunda ön tampon hasar gördü..."
|
| 177 |
-
),
|
| 178 |
-
lines=6
|
| 179 |
-
),
|
| 180 |
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
| 184 |
|
| 185 |
-
title="🛡️ Goshawk Insurance AI",
|
| 186 |
|
| 187 |
-
|
| 188 |
-
"Sigorta sektörüne özel DistilBERT yapay zeka modeli. "
|
| 189 |
-
"Sigorta metinlerini analiz ederek sınıflandırır."
|
| 190 |
-
),
|
| 191 |
|
| 192 |
-
|
| 193 |
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
|
|
|
|
|
|
|
|
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
if __name__ == "__main__":
|
| 204 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 205 |
demo.launch(
|
| 206 |
server_name="0.0.0.0",
|
| 207 |
-
server_port=
|
| 208 |
-
os.environ.get("PORT", 7860)
|
| 209 |
-
)
|
| 210 |
)
|
|
|
|
| 1 |
import os
|
| 2 |
import torch
|
| 3 |
import gradio as gr
|
| 4 |
+
|
| 5 |
+
from transformers import (
|
| 6 |
+
AutoTokenizer,
|
| 7 |
+
AutoModelForSequenceClassification
|
| 8 |
+
)
|
| 9 |
|
| 10 |
|
| 11 |
+
# ============================================================
|
| 12 |
# GOSHAWK INSURANCE AI
|
| 13 |
+
# DistilBERT - Insurance Classification
|
| 14 |
+
# CPU OPTIMIZED
|
| 15 |
+
# ============================================================
|
| 16 |
|
|
|
|
|
|
|
| 17 |
MODEL_PATH = "./"
|
|
|
|
| 18 |
DEVICE = torch.device("cpu")
|
| 19 |
|
| 20 |
+
MAX_LENGTH = 256
|
| 21 |
+
|
| 22 |
|
| 23 |
+
# ============================================================
|
| 24 |
+
# MODEL YÜKLEME
|
| 25 |
+
# ============================================================
|
| 26 |
|
| 27 |
+
print("=" * 60)
|
| 28 |
print("GOSHAWK INSURANCE AI")
|
| 29 |
print("Model yükleniyor...")
|
| 30 |
+
print("=" * 60)
|
| 31 |
|
| 32 |
try:
|
| 33 |
+
|
| 34 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 35 |
MODEL_PATH,
|
| 36 |
local_files_only=True
|
|
|
|
| 44 |
model.to(DEVICE)
|
| 45 |
model.eval()
|
| 46 |
|
| 47 |
+
except Exception as error:
|
| 48 |
+
|
| 49 |
+
print("=" * 60)
|
| 50 |
+
print("MODEL YÜKLEME HATASI")
|
| 51 |
+
print(error)
|
| 52 |
+
print("=" * 60)
|
| 53 |
+
|
| 54 |
+
raise error
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# ============================================================
|
| 58 |
+
# MODEL BİLGİLERİ
|
| 59 |
+
# ============================================================
|
| 60 |
+
|
| 61 |
+
print("=" * 60)
|
| 62 |
+
print("MODEL BAŞARIYLA YÜKLENDİ")
|
| 63 |
+
print("=" * 60)
|
| 64 |
+
|
| 65 |
+
print("Device:", DEVICE)
|
| 66 |
+
print("Model:", type(model).__name__)
|
| 67 |
+
print("Num labels:", model.config.num_labels)
|
| 68 |
+
|
| 69 |
+
print("ID2LABEL:")
|
| 70 |
+
print(model.config.id2label)
|
| 71 |
+
|
| 72 |
+
print("LABEL2ID:")
|
| 73 |
+
print(model.config.label2id)
|
| 74 |
+
|
| 75 |
+
print("=" * 60)
|
| 76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
+
# ============================================================
|
| 79 |
+
# LABEL OKUMA
|
| 80 |
+
# ============================================================
|
| 81 |
|
| 82 |
+
def get_label(index):
|
| 83 |
+
|
| 84 |
+
label = model.config.id2label.get(
|
| 85 |
+
index,
|
| 86 |
+
f"LABEL_{index}"
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
return str(label)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
# ============================================================
|
| 93 |
+
# METİN ANALİZİ
|
| 94 |
+
# ============================================================
|
| 95 |
|
| 96 |
def predict(text):
|
| 97 |
|
| 98 |
+
# Boş metin kontrolü
|
| 99 |
if text is None or not text.strip():
|
| 100 |
+
|
| 101 |
return {
|
| 102 |
+
"Durum": "HATA",
|
| 103 |
+
"Mesaj": "Lütfen bir sigorta metni girin."
|
| 104 |
}
|
| 105 |
|
| 106 |
+
|
| 107 |
text = text.strip()
|
| 108 |
|
| 109 |
+
|
| 110 |
try:
|
| 111 |
|
| 112 |
+
# ----------------------------------------------------
|
| 113 |
+
# TOKENIZER
|
| 114 |
+
# ----------------------------------------------------
|
| 115 |
+
|
| 116 |
inputs = tokenizer(
|
| 117 |
text,
|
| 118 |
return_tensors="pt",
|
| 119 |
truncation=True,
|
| 120 |
padding=True,
|
| 121 |
+
max_length=MAX_LENGTH
|
| 122 |
)
|
| 123 |
|
| 124 |
+
|
| 125 |
+
# ----------------------------------------------------
|
| 126 |
# CPU
|
| 127 |
+
# ----------------------------------------------------
|
| 128 |
+
|
| 129 |
inputs = {
|
| 130 |
key: value.to(DEVICE)
|
| 131 |
for key, value in inputs.items()
|
| 132 |
}
|
| 133 |
|
| 134 |
+
|
| 135 |
+
# ----------------------------------------------------
|
| 136 |
+
# MODEL
|
| 137 |
+
# ----------------------------------------------------
|
| 138 |
+
|
| 139 |
with torch.inference_mode():
|
| 140 |
|
| 141 |
outputs = model(**inputs)
|
| 142 |
|
| 143 |
+
logits = outputs.logits[0]
|
| 144 |
+
|
| 145 |
probabilities = torch.softmax(
|
| 146 |
+
logits,
|
| 147 |
dim=-1
|
| 148 |
+
)
|
| 149 |
|
|
|
|
|
|
|
| 150 |
|
| 151 |
+
# ----------------------------------------------------
|
| 152 |
+
# TÜM SINIFLAR
|
| 153 |
+
# ----------------------------------------------------
|
| 154 |
|
| 155 |
+
all_results = {}
|
| 156 |
+
|
| 157 |
+
for index in range(model.config.num_labels):
|
|
|
|
| 158 |
|
| 159 |
+
label = get_label(index)
|
| 160 |
+
|
| 161 |
+
probability = float(
|
| 162 |
+
probabilities[index]
|
| 163 |
+
) * 100
|
| 164 |
+
|
| 165 |
+
all_results[label] = round(
|
| 166 |
+
probability,
|
| 167 |
2
|
| 168 |
)
|
| 169 |
|
| 170 |
+
|
| 171 |
+
# ----------------------------------------------------
|
| 172 |
+
# EN YÜKSEK SINIF
|
| 173 |
+
# ----------------------------------------------------
|
| 174 |
+
|
| 175 |
+
best_index = int(
|
| 176 |
+
torch.argmax(probabilities)
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
best_label = get_label(best_index)
|
| 180 |
+
|
| 181 |
+
best_probability = (
|
| 182 |
+
float(probabilities[best_index]) * 100
|
| 183 |
)
|
| 184 |
|
|
|
|
| 185 |
|
| 186 |
+
# ----------------------------------------------------
|
| 187 |
+
# SIRALA
|
| 188 |
+
# ----------------------------------------------------
|
| 189 |
+
|
| 190 |
sorted_results = dict(
|
| 191 |
sorted(
|
| 192 |
+
all_results.items(),
|
| 193 |
+
key=lambda item: item[1],
|
| 194 |
reverse=True
|
| 195 |
)
|
| 196 |
)
|
| 197 |
|
| 198 |
+
|
| 199 |
+
# ----------------------------------------------------
|
| 200 |
+
# GÜVEN DURUMU
|
| 201 |
+
# ----------------------------------------------------
|
| 202 |
+
|
| 203 |
+
if best_probability >= 90:
|
| 204 |
+
|
| 205 |
+
confidence_status = "Çok yüksek"
|
| 206 |
+
|
| 207 |
+
elif best_probability >= 70:
|
| 208 |
+
|
| 209 |
+
confidence_status = "Yüksek"
|
| 210 |
+
|
| 211 |
+
elif best_probability >= 50:
|
| 212 |
+
|
| 213 |
+
confidence_status = "Orta"
|
| 214 |
+
|
| 215 |
+
else:
|
| 216 |
+
|
| 217 |
+
confidence_status = "Düşük"
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
# ----------------------------------------------------
|
| 221 |
+
# NEUTRAL KONTROLÜ
|
| 222 |
+
# ----------------------------------------------------
|
| 223 |
+
|
| 224 |
+
neutral_warning = ""
|
| 225 |
+
|
| 226 |
+
if (
|
| 227 |
+
"neutral" in best_label.lower()
|
| 228 |
+
and best_probability >= 90
|
| 229 |
+
):
|
| 230 |
+
|
| 231 |
+
neutral_warning = (
|
| 232 |
+
"Model Neutral sınıfına çok yüksek güven "
|
| 233 |
+
"veriyor. Farklı metinlerde de aynı sonuç "
|
| 234 |
+
"oluşuyorsa eğitim/label dağılımı kontrol "
|
| 235 |
+
"edilmelidir."
|
| 236 |
+
)
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
# ----------------------------------------------------
|
| 240 |
+
# SONUÇ
|
| 241 |
+
# ----------------------------------------------------
|
| 242 |
+
|
| 243 |
return {
|
| 244 |
+
|
| 245 |
"Tahmin": best_label,
|
| 246 |
+
|
| 247 |
+
"Güven": (
|
| 248 |
+
f"{best_probability:.2f}%"
|
| 249 |
+
),
|
| 250 |
+
|
| 251 |
+
"Güven Durumu": confidence_status,
|
| 252 |
+
|
| 253 |
+
"Tüm Sınıflar": {
|
| 254 |
label: f"{score:.2f}%"
|
| 255 |
+
for label, score
|
| 256 |
+
in sorted_results.items()
|
| 257 |
+
},
|
| 258 |
+
|
| 259 |
+
"Neutral Kontrolü": neutral_warning,
|
| 260 |
+
|
| 261 |
+
"Model Bilgisi": {
|
| 262 |
+
|
| 263 |
+
"Model": type(model).__name__,
|
| 264 |
+
|
| 265 |
+
"Num Labels": model.config.num_labels,
|
| 266 |
+
|
| 267 |
+
"Device": str(DEVICE),
|
| 268 |
+
|
| 269 |
+
"Max Length": MAX_LENGTH
|
| 270 |
+
|
| 271 |
}
|
| 272 |
+
|
| 273 |
}
|
| 274 |
|
| 275 |
+
|
| 276 |
+
except Exception as error:
|
| 277 |
|
| 278 |
return {
|
| 279 |
+
|
| 280 |
+
"Durum": "MODEL HATASI",
|
| 281 |
+
|
| 282 |
+
"Hata": str(error)
|
| 283 |
+
|
| 284 |
}
|
| 285 |
|
| 286 |
|
| 287 |
+
# ============================================================
|
| 288 |
+
# TEST ÖRNEKLERİ
|
| 289 |
+
# ============================================================
|
| 290 |
|
| 291 |
examples = [
|
| 292 |
+
|
| 293 |
[
|
| 294 |
"Araç kazası sonucunda ön tampon ve far hasar gördü."
|
| 295 |
],
|
| 296 |
+
|
| 297 |
[
|
| 298 |
"Sigortalı kasko poliçesi kapsamında hasar başvurusunda bulundu."
|
| 299 |
],
|
| 300 |
+
|
| 301 |
+
[
|
| 302 |
+
"Trafik kazası nedeniyle araçta maddi hasar meydana geldi."
|
| 303 |
+
],
|
| 304 |
+
|
| 305 |
[
|
| 306 |
+
"Poliçe kapsamında sağlık giderlerinin karşılanması talep edildi."
|
| 307 |
],
|
| 308 |
+
|
| 309 |
[
|
| 310 |
+
"Sigorta şirketi hasar dosyasını inceleyerek ödeme yaptı."
|
| 311 |
],
|
| 312 |
+
|
| 313 |
[
|
| 314 |
+
"Sigortalının poliçe teminatı kapsamında tazminat talebi bulunmaktadır."
|
| 315 |
]
|
| 316 |
+
|
| 317 |
]
|
| 318 |
|
| 319 |
|
| 320 |
+
# ============================================================
|
| 321 |
+
# GRADIO ARAYÜZÜ
|
| 322 |
+
# ============================================================
|
| 323 |
|
| 324 |
+
with gr.Blocks(
|
| 325 |
+
title="Goshawk Insurance AI"
|
| 326 |
+
) as demo:
|
| 327 |
|
| 328 |
+
gr.Markdown(
|
| 329 |
+
"""
|
| 330 |
+
# 🛡️ Goshawk Insurance AI
|
| 331 |
|
| 332 |
+
**Sigorta sektörüne özel DistilBERT yapay zeka modeli**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
|
| 334 |
+
Sigorta metnini girin ve modelin hangi sınıfa
|
| 335 |
+
ait olduğunu tahmin etmesini sağlayın.
|
| 336 |
+
"""
|
| 337 |
+
)
|
| 338 |
|
|
|
|
| 339 |
|
| 340 |
+
with gr.Row():
|
|
|
|
|
|
|
|
|
|
| 341 |
|
| 342 |
+
with gr.Column():
|
| 343 |
|
| 344 |
+
text_input = gr.Textbox(
|
| 345 |
+
label="Sigorta Metni",
|
| 346 |
+
placeholder=(
|
| 347 |
+
"Örneğin: "
|
| 348 |
+
"Araç kazası nedeniyle ön tampon hasar gördü..."
|
| 349 |
+
),
|
| 350 |
+
lines=8
|
| 351 |
+
)
|
| 352 |
+
|
| 353 |
+
|
| 354 |
+
with gr.Row():
|
| 355 |
+
|
| 356 |
+
analyze_button = gr.Button(
|
| 357 |
+
"🔍 Analiz Et",
|
| 358 |
+
variant="primary"
|
| 359 |
+
)
|
| 360 |
|
| 361 |
+
clear_button = gr.Button(
|
| 362 |
+
"🗑️ Temizle"
|
| 363 |
+
)
|
| 364 |
|
| 365 |
+
|
| 366 |
+
with gr.Column():
|
| 367 |
+
|
| 368 |
+
output = gr.JSON(
|
| 369 |
+
label="Model Sonucu"
|
| 370 |
+
)
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
# --------------------------------------------------------
|
| 374 |
+
# ÖRNEKLER
|
| 375 |
+
# --------------------------------------------------------
|
| 376 |
+
|
| 377 |
+
gr.Examples(
|
| 378 |
+
examples=examples,
|
| 379 |
+
inputs=text_input,
|
| 380 |
+
label="Örnek Sigorta Metinleri"
|
| 381 |
+
)
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
# --------------------------------------------------------
|
| 385 |
+
# BUTONLAR
|
| 386 |
+
# --------------------------------------------------------
|
| 387 |
+
|
| 388 |
+
analyze_button.click(
|
| 389 |
+
fn=predict,
|
| 390 |
+
inputs=text_input,
|
| 391 |
+
outputs=output
|
| 392 |
+
)
|
| 393 |
+
|
| 394 |
+
|
| 395 |
+
clear_button.click(
|
| 396 |
+
fn=lambda: "",
|
| 397 |
+
inputs=None,
|
| 398 |
+
outputs=text_input
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
# ============================================================
|
| 403 |
+
# SERVER
|
| 404 |
+
# ============================================================
|
| 405 |
|
| 406 |
if __name__ == "__main__":
|
| 407 |
|
| 408 |
+
port = int(
|
| 409 |
+
os.environ.get(
|
| 410 |
+
"PORT",
|
| 411 |
+
7860
|
| 412 |
+
)
|
| 413 |
+
)
|
| 414 |
+
|
| 415 |
demo.launch(
|
| 416 |
server_name="0.0.0.0",
|
| 417 |
+
server_port=port
|
|
|
|
|
|
|
| 418 |
)
|