Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ from sklearn.preprocessing import MinMaxScaler, LabelEncoder
|
|
| 4 |
from sklearn.metrics import accuracy_score
|
| 5 |
from concrete.ml.sklearn import XGBClassifier as ConcreteXGBClassifier
|
| 6 |
from concrete.ml.deployment import FHEModelDev, FHEModelClient, FHEModelServer
|
| 7 |
-
import shutil
|
| 8 |
import os
|
| 9 |
|
| 10 |
|
|
@@ -80,7 +79,7 @@ def compute_ratios(df: pd.DataFrame) -> pd.DataFrame:
|
|
| 80 |
df["Finansal Kaldıraç"] = safe_div(tl * 100, ta)
|
| 81 |
df["Stok Devir Hızı"] = -safe_div(df["Satışların Maliyeti (-)"], df["Stoklar"])
|
| 82 |
|
| 83 |
-
# Altman Z-
|
| 84 |
X1 = safe_div(df["Dönen Varlıklar"] - df["Kısa Vadeli Yükümlülükler"], ta)
|
| 85 |
X2 = safe_div(df["Geçmiş Yıllar Kar/Zararları"] + df["Dönem Net Kar/Zararı"], ta)
|
| 86 |
X3 = safe_div(df["SÜRDÜRÜLEN FAALİYETLER VERGİ ÖNCESİ KARI (ZARARI)"], ta)
|
|
@@ -148,7 +147,7 @@ grid = GridSearchCV(
|
|
| 148 |
grid.fit(Xtr_s, ytr_e)
|
| 149 |
best_params = grid.best_params_
|
| 150 |
|
| 151 |
-
#
|
| 152 |
full_plain = ConcreteXGBClassifier(n_bits=8, **best_params, random_state=42)
|
| 153 |
full_plain.fit(Xtr_s, ytr_e)
|
| 154 |
|
|
@@ -179,6 +178,7 @@ for i, col in enumerate(COLS, 1):
|
|
| 179 |
|
| 180 |
|
| 181 |
# ------------------------ FONKSİYONLAR ------------------------
|
|
|
|
| 182 |
|
| 183 |
def generate_keys():
|
| 184 |
global client
|
|
@@ -208,14 +208,14 @@ def encrypt_excel(file):
|
|
| 208 |
if client is None:
|
| 209 |
raise gr.Error("Lütfen önce 'Anahtar Oluştur'a tıklayın.")
|
| 210 |
|
| 211 |
-
# Yeni yükleme geldiğinde önceki tahminleri sıfırla
|
| 212 |
encrypted_output = None
|
| 213 |
fhe_prediction_ready = False
|
| 214 |
simulate_prediction = []
|
| 215 |
|
| 216 |
df = pd.read_excel(file.name, header=None).set_index(0).T.reset_index(drop=True)
|
| 217 |
|
| 218 |
-
#
|
| 219 |
df.columns = df.columns.str.strip()
|
| 220 |
df = df.loc[:, ~df.columns.duplicated()]
|
| 221 |
df.rename(columns={"Desc": "Periyot"}, inplace=True)
|
|
@@ -229,7 +229,7 @@ def encrypt_excel(file):
|
|
| 229 |
|
| 230 |
scaled = scaler_sel.transform(X_input)
|
| 231 |
|
| 232 |
-
# Her satırı ayrı ayrı şifrele
|
| 233 |
encrypted_list = []
|
| 234 |
for row in scaled:
|
| 235 |
row = row.reshape(1, -1)
|
|
@@ -402,9 +402,9 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue")) as demo:
|
|
| 402 |
gr.Examples(examples=EXAMPLE_XLSX, inputs=file_in, label="Örnek Excel Seç", cache_examples=False)
|
| 403 |
|
| 404 |
if __name__ == "__main__":
|
| 405 |
-
|
| 406 |
fhe_prediction_ready = False
|
| 407 |
simulate_prediction = []
|
| 408 |
encrypted_output = None
|
| 409 |
|
| 410 |
-
demo.launch()
|
|
|
|
| 4 |
from sklearn.metrics import accuracy_score
|
| 5 |
from concrete.ml.sklearn import XGBClassifier as ConcreteXGBClassifier
|
| 6 |
from concrete.ml.deployment import FHEModelDev, FHEModelClient, FHEModelServer
|
|
|
|
| 7 |
import os
|
| 8 |
|
| 9 |
|
|
|
|
| 79 |
df["Finansal Kaldıraç"] = safe_div(tl * 100, ta)
|
| 80 |
df["Stok Devir Hızı"] = -safe_div(df["Satışların Maliyeti (-)"], df["Stoklar"])
|
| 81 |
|
| 82 |
+
# Altman Z-Skoru
|
| 83 |
X1 = safe_div(df["Dönen Varlıklar"] - df["Kısa Vadeli Yükümlülükler"], ta)
|
| 84 |
X2 = safe_div(df["Geçmiş Yıllar Kar/Zararları"] + df["Dönem Net Kar/Zararı"], ta)
|
| 85 |
X3 = safe_div(df["SÜRDÜRÜLEN FAALİYETLER VERGİ ÖNCESİ KARI (ZARARI)"], ta)
|
|
|
|
| 147 |
grid.fit(Xtr_s, ytr_e)
|
| 148 |
best_params = grid.best_params_
|
| 149 |
|
| 150 |
+
# Özellik seçimi
|
| 151 |
full_plain = ConcreteXGBClassifier(n_bits=8, **best_params, random_state=42)
|
| 152 |
full_plain.fit(Xtr_s, ytr_e)
|
| 153 |
|
|
|
|
| 178 |
|
| 179 |
|
| 180 |
# ------------------------ FONKSİYONLAR ------------------------
|
| 181 |
+
import shutil
|
| 182 |
|
| 183 |
def generate_keys():
|
| 184 |
global client
|
|
|
|
| 208 |
if client is None:
|
| 209 |
raise gr.Error("Lütfen önce 'Anahtar Oluştur'a tıklayın.")
|
| 210 |
|
| 211 |
+
# 🧹 Yeni yükleme geldiğinde önceki tahminleri sıfırla
|
| 212 |
encrypted_output = None
|
| 213 |
fhe_prediction_ready = False
|
| 214 |
simulate_prediction = []
|
| 215 |
|
| 216 |
df = pd.read_excel(file.name, header=None).set_index(0).T.reset_index(drop=True)
|
| 217 |
|
| 218 |
+
# 🧼 Temizlik işlemleri
|
| 219 |
df.columns = df.columns.str.strip()
|
| 220 |
df = df.loc[:, ~df.columns.duplicated()]
|
| 221 |
df.rename(columns={"Desc": "Periyot"}, inplace=True)
|
|
|
|
| 229 |
|
| 230 |
scaled = scaler_sel.transform(X_input)
|
| 231 |
|
| 232 |
+
# 🔐 Her satırı ayrı ayrı şifrele
|
| 233 |
encrypted_list = []
|
| 234 |
for row in scaled:
|
| 235 |
row = row.reshape(1, -1)
|
|
|
|
| 402 |
gr.Examples(examples=EXAMPLE_XLSX, inputs=file_in, label="Örnek Excel Seç", cache_examples=False)
|
| 403 |
|
| 404 |
if __name__ == "__main__":
|
| 405 |
+
print("✅ Gradio app is launching...")
|
| 406 |
fhe_prediction_ready = False
|
| 407 |
simulate_prediction = []
|
| 408 |
encrypted_output = None
|
| 409 |
|
| 410 |
+
demo.launch()
|