Spaces:
Sleeping
Sleeping
Update app/main.py (#56)
Browse files- Update app/main.py (2805a75390c7ba3686765c52b681d579455bb2ab)
Co-authored-by: Axel Rousseau <axelrvite@users.noreply.huggingface.co>
- app/main.py +10 -5
app/main.py
CHANGED
|
@@ -42,7 +42,12 @@ async def predict(file: UploadFile = File(...)):
|
|
| 42 |
# Vérification du type de fichier
|
| 43 |
if not file.filename.endswith('.csv'):
|
| 44 |
raise HTTPException(status_code=400, detail="Le fichier doit être au format CSV")
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# Création d'un fichier temporaire
|
| 47 |
temp_filename = f"{uuid.uuid4()}_{file.filename}"
|
| 48 |
temp_filepath = os.path.join(TEMP_DIR, temp_filename)
|
|
@@ -56,7 +61,7 @@ async def predict(file: UploadFile = File(...)):
|
|
| 56 |
exp_points = read_iv_csv(temp_filepath)
|
| 57 |
|
| 58 |
# Analyse par méthode classique (Random)
|
| 59 |
-
fit_random = Fit_IV(temp_filepath, ",", type_fit="RANDOM")
|
| 60 |
params_random = {
|
| 61 |
"Rsh": fit_random.params_fit["Rsh"],
|
| 62 |
"Rs": fit_random.params_fit["Rs"],
|
|
@@ -68,7 +73,7 @@ async def predict(file: UploadFile = File(...)):
|
|
| 68 |
ssd_random = fit_random.ssd_fit
|
| 69 |
|
| 70 |
# Analyse par méthode génétique
|
| 71 |
-
fit_genetique = Fit_IV(temp_filepath, ",", type_fit="GENETIQUE")
|
| 72 |
params_genetique = {
|
| 73 |
"Rsh": fit_genetique.params_fit["Rsh"],
|
| 74 |
"Rs": fit_genetique.params_fit["Rs"],
|
|
@@ -80,13 +85,13 @@ async def predict(file: UploadFile = File(...)):
|
|
| 80 |
ssd_genetique = fit_genetique.ssd_fit
|
| 81 |
|
| 82 |
# Analyse par MLP
|
| 83 |
-
params_mlp, I_mlp = comp_iv_curve(temp_filepath)
|
| 84 |
# Calcul du SSD pour MLP
|
| 85 |
I_exp = np.array([point[1] for point in exp_points])
|
| 86 |
ssd_mlp = np.mean((I_exp - I_mlp) ** 2)
|
| 87 |
|
| 88 |
# Analyse par CNN1D
|
| 89 |
-
params_cnn, I_cnn = comp_iv_curve_cnn1d(temp_filepath)
|
| 90 |
# Calcul du SSD pour CNN
|
| 91 |
ssd_cnn = np.mean((I_exp - I_cnn) ** 2)
|
| 92 |
|
|
|
|
| 42 |
# Vérification du type de fichier
|
| 43 |
if not file.filename.endswith('.csv'):
|
| 44 |
raise HTTPException(status_code=400, detail="Le fichier doit être au format CSV")
|
| 45 |
+
name_file = file.filename
|
| 46 |
+
temperature = None
|
| 47 |
+
if name_file.split('_', 1)[0] == "Polyspace" or name_file.split('_', 1)[0] == "polyspace":
|
| 48 |
+
print("temperature", temperature)
|
| 49 |
+
temperature = name_file.rsplit('_', 1)[-1]
|
| 50 |
+
|
| 51 |
# Création d'un fichier temporaire
|
| 52 |
temp_filename = f"{uuid.uuid4()}_{file.filename}"
|
| 53 |
temp_filepath = os.path.join(TEMP_DIR, temp_filename)
|
|
|
|
| 61 |
exp_points = read_iv_csv(temp_filepath)
|
| 62 |
|
| 63 |
# Analyse par méthode classique (Random)
|
| 64 |
+
fit_random = Fit_IV(temp_filepath, ",", type_fit="RANDOM", temperature)
|
| 65 |
params_random = {
|
| 66 |
"Rsh": fit_random.params_fit["Rsh"],
|
| 67 |
"Rs": fit_random.params_fit["Rs"],
|
|
|
|
| 73 |
ssd_random = fit_random.ssd_fit
|
| 74 |
|
| 75 |
# Analyse par méthode génétique
|
| 76 |
+
fit_genetique = Fit_IV(temp_filepath, ",", type_fit="GENETIQUE", temperature)
|
| 77 |
params_genetique = {
|
| 78 |
"Rsh": fit_genetique.params_fit["Rsh"],
|
| 79 |
"Rs": fit_genetique.params_fit["Rs"],
|
|
|
|
| 85 |
ssd_genetique = fit_genetique.ssd_fit
|
| 86 |
|
| 87 |
# Analyse par MLP
|
| 88 |
+
params_mlp, I_mlp = comp_iv_curve(temp_filepath, temperature)
|
| 89 |
# Calcul du SSD pour MLP
|
| 90 |
I_exp = np.array([point[1] for point in exp_points])
|
| 91 |
ssd_mlp = np.mean((I_exp - I_mlp) ** 2)
|
| 92 |
|
| 93 |
# Analyse par CNN1D
|
| 94 |
+
params_cnn, I_cnn = comp_iv_curve_cnn1d(temp_filepath, temperature)
|
| 95 |
# Calcul du SSD pour CNN
|
| 96 |
ssd_cnn = np.mean((I_exp - I_cnn) ** 2)
|
| 97 |
|