-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_text2.py
More file actions
60 lines (47 loc) · 1.85 KB
/
Copy pathtest_text2.py
File metadata and controls
60 lines (47 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import pandas as pd
import numpy as np
from tensorflow.keras.models import load_model
from sklearn.preprocessing import StandardScaler
import json
# Load model
model = load_model("model/disease_model.h5")
# Load processed DataFrame
df_encoded = pd.read_csv("dataset/processed_df.csv")
X = df_encoded.drop(columns=["Disease_label"])
# Fit scaler
scaler = StandardScaler()
scaler.fit(X)
# Load class map
with open("disease_classes.json") as f:
label_map = json.load(f)
label_map = {int(k): v for k, v in label_map.items()}
# Get column names
all_features = list(X.columns)
while True:
print("\n Testare model AI cu date introduse manual:")
try:
age = float(input(" Introduceți vârsta animalului: "))
temp = float(input(" Introduceți temperatura (Fahrenheit): "))
animal = input(" Alegeți animalul (cow, goat, sheep, buffalo): ").strip().lower()
symptoms = input(" Introduceți simptome separate prin virgulă: ").strip().lower().split(",")
symptoms = [s.strip() for s in symptoms]
animal_col = f"Animal_{animal}"
if animal_col not in all_features:
print(f" Animal invalid: {animal}")
continue
# Build input vector
input_dict = {col: 0 for col in all_features}
input_dict["Age"] = age
input_dict["Temperature"] = temp
input_dict[animal_col] = 1
for sym_col in all_features:
for s in symptoms:
if s and s in sym_col.lower():
input_dict[sym_col] = 1
input_vector = [input_dict[col] for col in all_features]
input_scaled = scaler.transform([input_vector])
prediction = model.predict(input_scaled)
predicted_class = np.argmax(prediction, axis=1)[0]
print(f"\nPredicție: {label_map[predicted_class]}")
except Exception as e:
print(f"Eroare: {e}")