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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""
|
| 3 |
+
tree_age_iks_300_tamil.py
|
| 4 |
+
AI மர வகை மற்றும் வயது கணிப்பு (300 இனியோட்டப் பெயர்கள்) + IKS (தமிழ்) இணைப்பு
|
| 5 |
+
Author: Generated for user
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import streamlit as st
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
import json
|
| 12 |
+
import math
|
| 13 |
+
import numpy as np
|
| 14 |
+
import pandas as pd
|
| 15 |
+
from sklearn.tree import DecisionTreeClassifier
|
| 16 |
+
|
| 17 |
+
# ----------------------------
|
| 18 |
+
# 1) 300 species list (primary list)
|
| 19 |
+
# ----------------------------
|
| 20 |
+
species_names = [
|
| 21 |
+
"mango","neem","banyan","peepal","teak","sal","sandalwood","rosewood","mahogany","acacia",
|
| 22 |
+
"babool","ashoka","gulmohar","rain tree","eucalyptus","jamun","guava","jackfruit","tamarind","coconut",
|
| 23 |
+
"areca palm","rubber","casuarina","bamboo","fig","amla","drumstick","kadamba","pongamia","arjuna",
|
| 24 |
+
"bael","custard apple","flame tree","indian almond","bottlebrush","silk cotton","indian coral","kadam","siris","subabul",
|
| 25 |
+
"albizia","karanja","tulip tree","silver oak","pine","deodar","oak","maple","ash","cedar",
|
| 26 |
+
"cypress","willow","poplar","birch","cashew","papaya","banana","mulberry","tendu","indian cherry",
|
| 27 |
+
"sapota","mangosteen","clove","nutmeg","coffee","tea","black pepper","cinnamon","neer maruthu","palmyra",
|
| 28 |
+
"date palm","cork tree","white teak","pungam","champa","plumeria","mahua","red cedar","apple","pear",
|
| 29 |
+
"peach","cherry","almond","walnut","plum","apricot","persimmon","betel nut","wild jack","neer fig",
|
| 30 |
+
"siris tree","arjun variant","custard variant","amla variant","rosewood variant","rain tree variant",
|
| 31 |
+
"ashoka variant","banyan variant","guava variant","neem variant",
|
| 32 |
+
"hibiscus","bougainvillea","jasmine","marigold","tulsi","mint","basil","lemongrass","oregano","thyme",
|
| 33 |
+
"rosemary","sage","aloevera","ginger","turmeric","galangal","cardamom","fennel","coriander","cumin",
|
| 34 |
+
"fenugreek","castor","sunflower","sesame","mustard","linseed","hemp","cotton","okra","brinjal",
|
| 35 |
+
"tomato","chili","potato","onion","garlic","spinach","amaranthus","cauliflower","cabbage","broccoli",
|
| 36 |
+
"pumpkin","ridge gourd","bottle gourd","bitter gourd","snake gourd","cucumber","watermelon","muskmelon","melon","lettuce",
|
| 37 |
+
"beetroot","carrot","radish","turnip","yam","sweet potato","colocasia","cassava","arrowroot","peppermint",
|
| 38 |
+
"sagebrush","lavender","thyme variant","oregano variant","mint variant","bamboo palm","traveller’s palm","fan palm","sago palm","royal palm",
|
| 39 |
+
"silver date palm","foxtail palm","betel leaf","vanilla","kokum","kokum tree","soursop","star fruit","breadfruit","durian",
|
| 40 |
+
"custard pear","sugar apple","dragon fruit","kiwi","pomegranate","blueberry","strawberry","blackberry","raspberry","cranberry",
|
| 41 |
+
"gooseberry","tamarillo","lychee","longan","rambutan","fig variant","mulberry variant","lemon","lime","orange",
|
| 42 |
+
"grapefruit","pomelo","citron","mandarin","tangerine","lemondrop mangosteen","miracle fruit","noni","baobab","acacia nilotica",
|
| 43 |
+
"prosopis juliflora","dalbergia latifolia","terminalia bellirica","terminalia chebula","emblica officinalis","cassia fistula","delonix regia","bauhinia purpurea","bauhinia variegata","peltophorum pterocarpum",
|
| 44 |
+
"lagerstroemia speciosa","millingtonia hortensis","polyalthia longifolia","ficus benghalensis","ficus religiosa","ficus racemosa","ficus elastica","artocarpus heterophyllus","artocarpus altilis","azadirachta indica",
|
| 45 |
+
"swietenia mahagoni","mimusops elengi","syzygium cumini","eucalyptus globulus","grevillea robusta","santalum album","pterospermum acerifolium","butea monosperma","madhuca longifolia","pithecellobium dulce",
|
| 46 |
+
"callistemon citrinus","cassia siamea","cassia javanica","albizia lebbeck","albizia saman","alstonia scholaris","antidesma acidum","barringtonia acutangula","careya arborea","cochlospermum religiosum",
|
| 47 |
+
"cordia dichotoma","croton bonplandianum","crataeva magna","dillenia indica","diospyros melanoxylon","erythrina variegata","feronia limonia","grewia asiatica","holarrhena pubescens","manilkara zapota",
|
| 48 |
+
"morinda tinctoria","polyalthia longifolia pendula","putranjiva roxburghii","sapindus trifoliatus","semecarpus anacardium","sterculia urens","syzygium aromaticum","tamarindus indica","terminalia arjuna","trichilia emetica",
|
| 49 |
+
"wrightia tinctoria","ziziphus mauritiana","ziziphus jujuba","adansonia digitata","hevea brasiliensis","catharanthus roseus","melia dubia","moringa oleifera","melia azedarach","saraca asoca",
|
| 50 |
+
"michelia champaca","magnolia grandiflora","tithonia diversifolia","melastoma malabathricum","thespesia populnea","vetiver","lemongrass variant","camphor tree","guaiacum officinale","annona reticulata",
|
| 51 |
+
"artemisia annua","tulsi krishna","neem hybrid","mahogany hybrid","sandalwood hybrid","rosewood hybrid","amla hybrid","eucalyptus hybrid","gulmohar hybrid","casuarina hybrid"
|
| 52 |
+
]
|
| 53 |
+
|
| 54 |
+
# ensure exactly 300 (if earlier list shorter, extend with generated names)
|
| 55 |
+
if len(species_names) < 300:
|
| 56 |
+
idx = len(species_names) + 1
|
| 57 |
+
while len(species_names) < 300:
|
| 58 |
+
species_names.append(f"species_{idx}")
|
| 59 |
+
idx += 1
|
| 60 |
+
elif len(species_names) > 300:
|
| 61 |
+
species_names = species_names[:300]
|
| 62 |
+
|
| 63 |
+
# ----------------------------
|
| 64 |
+
# 2) Create minimal synthetic attributes for classifier
|
| 65 |
+
# (kept simple: leaf_shape, bark_texture, habitat, fruit_presence, avg height, leaf size, growth_factor)
|
| 66 |
+
# ----------------------------
|
| 67 |
+
np.random.seed(42)
|
| 68 |
+
species_data = {
|
| 69 |
+
"species": species_names,
|
| 70 |
+
"leaf_shape": np.random.choice(["broad","oval","needle","compound","heart","lanceolate"], len(species_names)),
|
| 71 |
+
"bark_texture": np.random.choice(["smooth","rough","flaky","fibrous","grooved"], len(species_names)),
|
| 72 |
+
"habitat": np.random.choice(["tropical","dry","coastal","hill","plain","rainforest"], len(species_names)),
|
| 73 |
+
"fruit_presence": np.random.choice(["yes","no"], len(species_names)),
|
| 74 |
+
"average_height_m": np.round(np.random.uniform(2, 60, len(species_names)), 2),
|
| 75 |
+
"leaf_size_cm": np.round(np.random.uniform(2, 45, len(species_names)), 2),
|
| 76 |
+
# growth_factor used to compute age = (circumference/pi) * growth_factor
|
| 77 |
+
"growth_factor": np.round(np.random.uniform(1.4, 5.0, len(species_names)), 2)
|
| 78 |
+
}
|
| 79 |
+
df_species = pd.DataFrame(species_data)
|
| 80 |
+
|
| 81 |
+
# ----------------------------
|
| 82 |
+
# 3) Train a Decision Tree on this lightweight synthetic table
|
| 83 |
+
# ----------------------------
|
| 84 |
+
X = pd.get_dummies(df_species[["leaf_shape","bark_texture","habitat","fruit_presence"]])
|
| 85 |
+
X["average_height_m"] = df_species["average_height_m"]
|
| 86 |
+
X["leaf_size_cm"] = df_species["leaf_size_cm"]
|
| 87 |
+
y = df_species["species"]
|
| 88 |
+
|
| 89 |
+
clf = DecisionTreeClassifier(random_state=42, max_depth=14)
|
| 90 |
+
clf.fit(X, y)
|
| 91 |
+
|
| 92 |
+
# ----------------------------
|
| 93 |
+
# 4) IKS Tamil knowledge base (prepopulated entries for many common species)
|
| 94 |
+
# File path for persistence
|
| 95 |
+
# ----------------------------
|
| 96 |
+
IKS_DB_PATH = "iks_tamil_300_db.json"
|
| 97 |
+
|
| 98 |
+
# Prepopulate Tamil IKS entries for commonly known species.
|
| 99 |
+
# For many of the 300 species we provide a default placeholder.
|
| 100 |
+
prepopulated = {
|
| 101 |
+
# Common examples (Tamil name, uses, notes) - you can expand/edit later
|
| 102 |
+
"mango": {
|
| 103 |
+
"tamil_name": "மாமரம்",
|
| 104 |
+
"english_name": "Mango",
|
| 105 |
+
"uses_tamil": "மாமரப் பழம் உணவாக பயன்படும்; இலைகள், கூழ்கள் பல மருந்து பயன்பாடுகள்.",
|
| 106 |
+
"notes_tamil": "பாரம்பரியமாக இந்தியாவில் மதிப்பிடப்பட்ட மரம்; பல்வேறு பழவகைகள் உண்டு."
|
| 107 |
+
},
|
| 108 |
+
"neem": {
|
| 109 |
+
"tamil_name": "வேம்பு",
|
| 110 |
+
"english_name": "Neem",
|
| 111 |
+
"uses_tamil": "வழக்கமாக கிருமிநாசினியாகவும், தோல் மருத்துவமாகவும் பயன்படும்; பல் பராமரிப்பிலும் பயன்பாடு.",
|
| 112 |
+
"notes_tamil": "பாரம்பரிய மருத்துவத்தில் முக்கியத்துவம் அதிகம்."
|
| 113 |
+
},
|
| 114 |
+
"banyan": {
|
| 115 |
+
"tamil_name": "ஆலமரம்",
|
| 116 |
+
"english_name": "Banyan",
|
| 117 |
+
"uses_tamil": "பரப்பாக்க மகத்தான நிழல்; வழிபாட்டு மற்றும் சமூக சந்த்பிரதிபலனில் முக்கியம்.",
|
| 118 |
+
"notes_tamil": "பழைய மரங்களின் வாழ்நாள் நீண்டது."
|
| 119 |
+
},
|
| 120 |
+
"peepal": {
|
| 121 |
+
"tamil_name": "பீப்பல்",
|
| 122 |
+
"english_name": "Peepal",
|
| 123 |
+
"uses_tamil": "மத வழிபாடு மற்றும் மரபுத்தனத்தின் அடையாளம்; சிலர் மருத்துவபயன்பாட்டு குறிப்புகளை மேற்கோள் செய்கிறார்கள்.",
|
| 124 |
+
"notes_tamil": "வளர்ச்சி மேலாண்மைக்கு பரவலாக பயனுள்ளது."
|
| 125 |
+
},
|
| 126 |
+
"teak": {
|
| 127 |
+
"tamil_name": "தேக்கு",
|
| 128 |
+
"english_name": "Teak",
|
| 129 |
+
"uses_tamil": "முதன்மையாக கட்டிடக்கலை மற்றும் கப்பல் பணிக்குப் பயன்படும் வலுவான மரம்.",
|
| 130 |
+
"notes_tamil": "ஊரக மற்றும் வணிக மர வனம்."
|
| 131 |
+
},
|
| 132 |
+
"coconut": {
|
| 133 |
+
"tamil_name": "தென்னை",
|
| 134 |
+
"english_name": "Coconut",
|
| 135 |
+
"uses_tamil": "பழம், எண்ணெய் மற்றும் பல பாவனைகளில் பயன்படும்; கடற்கரையில் பயன்பாடு அதிகம்.",
|
| 136 |
+
"notes_tamil": "வாழ்க்கை சார்ந்த மரம்; பலமருந்து பயன்பாடுகள்."
|
| 137 |
+
},
|
| 138 |
+
"amla": {
|
| 139 |
+
"tamil_name": "ஆமலா",
|
| 140 |
+
"english_name": "Amla",
|
| 141 |
+
"uses_tamil": "ஆயுர்வேதத்தில் முக்கியம்; C வைட்டமின் ஆதாரம்.",
|
| 142 |
+
"notes_tamil": "மருந்து மற்றும் உணவு பயன்பாடுகள்."
|
| 143 |
+
},
|
| 144 |
+
"drumstick": {
|
| 145 |
+
"tamil_name": "முருங்கை",
|
| 146 |
+
"english_name": "Drumstick (Moringa)",
|
| 147 |
+
"uses_tamil": "முருங்கை இலைகள், காய் மருத்துவ மற்றும் ஊட்டச்சத்து மூலமாக பயன்படும்.",
|
| 148 |
+
"notes_tamil": "குறைந்த நிலங்களில் வளர்ச்சி சிறந்தது."
|
| 149 |
+
},
|
| 150 |
+
# Add a few more explicit entries
|
| 151 |
+
"sandalwood": {
|
| 152 |
+
"tamil_name": "சந்தனம்",
|
| 153 |
+
"english_name": "Sandalwood",
|
| 154 |
+
"uses_tamil": "அருகம்பா வாசனை, மருந்து மற்றும் ஆன்மீகப் பயன்பாடுகள்.",
|
| 155 |
+
"notes_tamil": "மதிப்புமிக்க வெள்ளிமரப்பலு."
|
| 156 |
+
},
|
| 157 |
+
"jackfruit": {
|
| 158 |
+
"tamil_name": "பலாப்பழம்",
|
| 159 |
+
"english_name": "Jackfruit",
|
| 160 |
+
"uses_tamil": "காயும் பழமும் இரண்டுமே உணவாகவும், வணிகவாய்ப்புகளாகவும் இருக்கும்.",
|
| 161 |
+
"notes_tamil": "உணவு மற்றும் விவசாய பயன்பாடுகள் அதிகம்."
|
| 162 |
+
},
|
| 163 |
+
"guava": {
|
| 164 |
+
"tamil_name": "பேழை",
|
| 165 |
+
"english_name": "Guava",
|
| 166 |
+
"uses_tamil": "பழம், மருத்துவ பயன்பாடுகள் (விநோத தொற்று எதிர்ப்பு).",
|
| 167 |
+
"notes_tamil": "குடியரசு தோல் மற்றும் நன்மைகள்."
|
| 168 |
+
},
|
| 169 |
+
# default fallback entry
|
| 170 |
+
"default": {
|
| 171 |
+
"tamil_name": "",
|
| 172 |
+
"english_name": "",
|
| 173 |
+
"uses_tamil": "இந்த மரத்திற்கான பாரம்பரிய தகவல் தரவுத்தளத்தில் இல்லை. புதிய தகவலைச் சேர்க்கலாம்.",
|
| 174 |
+
"notes_tamil": "பயனாளர் IKS பதிவுகளை சேமிக்கலாம்."
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
# Load or create persistent IKS DB
|
| 179 |
+
if os.path.exists(IKS_DB_PATH):
|
| 180 |
+
try:
|
| 181 |
+
with open(IKS_DB_PATH, "r", encoding="utf-8") as f:
|
| 182 |
+
iks_db = json.load(f)
|
| 183 |
+
except Exception:
|
| 184 |
+
iks_db = prepopulated.copy()
|
| 185 |
+
else:
|
| 186 |
+
iks_db = prepopulated.copy()
|
| 187 |
+
try:
|
| 188 |
+
with open(IKS_DB_PATH, "w", encoding="utf-8") as f:
|
| 189 |
+
json.dump(iks_db, f, ensure_ascii=False, indent=2)
|
| 190 |
+
except Exception:
|
| 191 |
+
pass # continue even if file write not permitted
|
| 192 |
+
|
| 193 |
+
# ----------------------------
|
| 194 |
+
# Helper functions
|
| 195 |
+
# ----------------------------
|
| 196 |
+
def save_iks_entry(species_key, tamil_name, english_name, uses_tamil, notes_tamil):
|
| 197 |
+
key = species_key.lower()
|
| 198 |
+
iks_db[key] = {
|
| 199 |
+
"tamil_name": tamil_name,
|
| 200 |
+
"english_name": english_name,
|
| 201 |
+
"uses_tamil": uses_tamil,
|
| 202 |
+
"notes_tamil": notes_tamil
|
| 203 |
+
}
|
| 204 |
+
try:
|
| 205 |
+
with open(IKS_DB_PATH, "w", encoding="utf-8") as f:
|
| 206 |
+
json.dump(iks_db, f, ensure_ascii=False, indent=2)
|
| 207 |
+
return True
|
| 208 |
+
except Exception:
|
| 209 |
+
return False
|
| 210 |
+
|
| 211 |
+
def get_iks_for_species(species_key):
|
| 212 |
+
key = species_key.lower()
|
| 213 |
+
if key in iks_db:
|
| 214 |
+
return iks_db[key]
|
| 215 |
+
# try normalized matching
|
| 216 |
+
key2 = key.replace(" ", "").replace("’", "").replace("'", "").lower()
|
| 217 |
+
for k in iks_db:
|
| 218 |
+
nk = k.replace(" ", "").replace("’", "").replace("'", "").lower()
|
| 219 |
+
if nk == key2:
|
| 220 |
+
return iks_db[k]
|
| 221 |
+
return iks_db.get("default")
|
| 222 |
+
|
| 223 |
+
def pretty_tamil_output(species, iks_entry, circumference_cm, diameter_cm, age_years):
|
| 224 |
+
tamil_lines = []
|
| 225 |
+
tamil_name = iks_entry.get("tamil_name") or species.capitalize()
|
| 226 |
+
eng_name = iks_entry.get("english_name") or ""
|
| 227 |
+
tamil_lines.append(f"🌳 மரம்: {tamil_name} ({eng_name} — {species})")
|
| 228 |
+
tamil_lines.append(f"📏 சுற்றளவு: {circumference_cm} cm")
|
| 229 |
+
tamil_lines.append(f"📐 விட்டம் (அளவு): {diameter_cm:.2f} cm")
|
| 230 |
+
tamil_lines.append(f"🕰️ கணிக்கப்பட்ட வயது: {age_years:.1f} ஆண்டு(கள்)")
|
| 231 |
+
tamil_lines.append("")
|
| 232 |
+
tamil_lines.append("🌿 பாரம்பரிய பயன்பாடுகள்:")
|
| 233 |
+
tamil_lines.append(iks_entry.get("uses_tamil", "தகவல் இல்லை"))
|
| 234 |
+
tamil_lines.append("")
|
| 235 |
+
tamil_lines.append("📝 குறிப்புகள்:")
|
| 236 |
+
tamil_lines.append(iks_entry.get("notes_tamil", "தகவல் இல்லை"))
|
| 237 |
+
return "\n".join(tamil_lines)
|
| 238 |
+
|
| 239 |
+
# ----------------------------
|
| 240 |
+
# 5) Main interactive loop (Tamil I/O friendly)
|
| 241 |
+
# ----------------------------
|
| 242 |
+
def main():
|
| 243 |
+
print("\n🌳 AI மர வகை மற்றும் வயது கணிப்பு (300 மரங்கள்) - IKS (தமிழ்) இணைப்பு\n")
|
| 244 |
+
print("கால்வெளி: இங்கே நீங்கள் கீழ்கண்ட விவரங்களை தமிழில் உள்ளீடு செய்யலாம்.")
|
| 245 |
+
print("இலை வடிவம்: broad/oval/needle/compound/heart/lanceolate")
|
| 246 |
+
print("தோல் அமைப்பு: smooth/rough/flaky/fibrous/grooved")
|
| 247 |
+
print("வாழ்விடம்: tropical/dry/coastal/hill/plain/rainforest")
|
| 248 |
+
print("பழம்: yes/no")
|
| 249 |
+
print("உதாரணமாக: ஒவல் -> 'oval', கடுமையான தோல் -> 'rough'\n")
|
| 250 |
+
|
| 251 |
+
# collect inputs (allow Tamil words mapped to English tokens)
|
| 252 |
+
def map_tamil_to_token(value):
|
| 253 |
+
v = value.strip().lower()
|
| 254 |
+
mapping = {
|
| 255 |
+
"பரந்த": "broad", "பரந்தது": "broad", "ஒவல்": "oval", "முள்": "needle",
|
| 256 |
+
"முழுகு": "needle", "சேர்க்கை": "compound", "இதயம்": "heart", "ஊசி": "lanceolate",
|
| 257 |
+
"அழுக்கு": "rough", "மென்மை": "smooth", "காசு": "flaky", "நார்": "fibrous", "துளை": "grooved",
|
| 258 |
+
"வெப்பமண்டல": "tropical", "வெப்ப": "tropical", "உலர்": "dry", "கடற்கரை": "coastal",
|
| 259 |
+
"மலை": "hill", "புலம்": "plain", "மழைக் காட்டில்": "rainforest", "மழைக்காடு": "rainforest",
|
| 260 |
+
"ஆம்": "yes", "இல்லை": "no", "உள்ளது": "yes", "இல்லாது": "no"
|
| 261 |
+
}
|
| 262 |
+
return mapping.get(v, v)
|
| 263 |
+
|
| 264 |
+
leaf_shape_in = input("இலை வடிவம் (தமிழில்/ஆங்கிலத்தில்): ")
|
| 265 |
+
leaf_shape = map_tamil_to_token(leaf_shape_in)
|
| 266 |
+
|
| 267 |
+
bark_texture_in = input("தோல் அமைப்பு (தமிழில்/ஆங்கிலத்தில்): ")
|
| 268 |
+
bark_texture = map_tamil_to_token(bark_texture_in)
|
| 269 |
+
|
| 270 |
+
habitat_in = input("வாழ்விடம் (தமிழில்/ஆங்கிலத்தில்): ")
|
| 271 |
+
habitat = map_tamil_to_token(habitat_in)
|
| 272 |
+
|
| 273 |
+
fruit_in = input("பழம் உள்ளதா? (ஆம்/இல்லை அல்லது yes/no): ")
|
| 274 |
+
fruit_presence = map_tamil_to_token(fruit_in)
|
| 275 |
+
|
| 276 |
+
try:
|
| 277 |
+
avg_height = float(input("சுமார் உயரம் (மீட்டர்): ").strip())
|
| 278 |
+
except Exception:
|
| 279 |
+
avg_height = float(np.mean(df_species["average_height_m"]))
|
| 280 |
+
|
| 281 |
+
try:
|
| 282 |
+
leaf_size = float(input("இலை அளவு (செ.மீ): ").strip())
|
| 283 |
+
except Exception:
|
| 284 |
+
leaf_size = float(np.mean(df_species["leaf_size_cm"]))
|
| 285 |
+
|
| 286 |
+
try:
|
| 287 |
+
circumference = float(input("மர சுற்றளவு (செ.மீ): ").strip())
|
| 288 |
+
except Exception:
|
| 289 |
+
print("தவறு: சுற்றளவை (cm) சரியாக உள்ளிடவும்.")
|
| 290 |
+
return
|
| 291 |
+
|
| 292 |
+
# prepare input for classifier
|
| 293 |
+
input_df = pd.DataFrame([{
|
| 294 |
+
"leaf_shape": leaf_shape,
|
| 295 |
+
"bark_texture": bark_texture,
|
| 296 |
+
"habitat": habitat,
|
| 297 |
+
"fruit_presence": fruit_presence
|
| 298 |
+
}])
|
| 299 |
+
input_encoded = pd.get_dummies(input_df)
|
| 300 |
+
input_encoded = input_encoded.reindex(columns=X.columns, fill_value=0)
|
| 301 |
+
input_encoded["average_height_m"] = avg_height
|
| 302 |
+
input_encoded["leaf_size_cm"] = leaf_size
|
| 303 |
+
|
| 304 |
+
# predict species
|
| 305 |
+
try:
|
| 306 |
+
predicted_species = clf.predict(input_encoded)[0]
|
| 307 |
+
except Exception as e:
|
| 308 |
+
print("வகைப்படுத்தலில் பிழை:", e)
|
| 309 |
+
predicted_species = species_names[0]
|
| 310 |
+
|
| 311 |
+
# lookup growth factor
|
| 312 |
+
gf_row = df_species.loc[df_species["species"] == predicted_species, "growth_factor"]
|
| 313 |
+
growth_factor = float(gf_row.values[0]) if len(gf_row) > 0 else float(np.mean(df_species["growth_factor"]))
|
| 314 |
+
|
| 315 |
+
# compute diameter and age
|
| 316 |
+
diameter_cm = circumference / math.pi
|
| 317 |
+
age_years = diameter_cm * growth_factor
|
| 318 |
+
|
| 319 |
+
# fetch IKS entry
|
| 320 |
+
iks_entry = get_iks_for_species(predicted_species)
|
| 321 |
+
|
| 322 |
+
# display results in Tamil
|
| 323 |
+
print("\n" + "-"*60 + "\n")
|
| 324 |
+
print(pretty_tamil_output(predicted_species, iks_entry, circumference, diameter_cm, age_years))
|
| 325 |
+
print("\n" + "-"*60 + "\n")
|
| 326 |
+
|
| 327 |
+
# Ask user if they want to add/edit IKS info for predicted species
|
| 328 |
+
add = input("இந்த மரத்திற்கான IKS தமிழ் தகவலை சேரிக்கவா/தொகு (y/n)? ").strip().lower()
|
| 329 |
+
if add == "y" or add == "ஆம்":
|
| 330 |
+
tamil_name = input("தமிழ் பெயர் (உதா: மாமரம்): ").strip()
|
| 331 |
+
eng_name = input("ஆங்கிலப் பெயர் (optional): ").strip()
|
| 332 |
+
uses = input("பாரம்பரிய / மருத்துவ பயன்பாடுகள் (தமிழில்): ").strip()
|
| 333 |
+
notes = input("குறிப்புகள் (தமிழில்): ").strip()
|
| 334 |
+
ok = save_iks_entry(predicted_species, tamil_name, eng_name, uses, notes)
|
| 335 |
+
if ok:
|
| 336 |
+
print("✅ IKS தகவல் வெற்றிகரமாக சேமிக்கப்பட்டது:", IKS_DB_PATH)
|
| 337 |
+
else:
|
| 338 |
+
print("⚠️ IKS தகவலை சேமிக்க முடியவில்லை (அனுமதி சோதிக்கவும்).")
|
| 339 |
+
|
| 340 |
+
# Continue loop?
|
| 341 |
+
again = input("\nமீண்டும் ஒரு மரத்தை மதிப்பிட வேண்டுமா? (y/n): ").strip().lower()
|
| 342 |
+
if again in ("y","yes","ஆம்"):
|
| 343 |
+
main()
|
| 344 |
+
else:
|
| 345 |
+
print("\nநன்றி! வாழ்த்துகள் 🌿")
|
| 346 |
+
return
|
| 347 |
+
|
| 348 |
+
if __name__ == "__main__":
|
| 349 |
+
try:
|
| 350 |
+
main()
|
| 351 |
+
except KeyboardInterrupt:
|
| 352 |
+
print("\nநீங்கள் செயலியை நிறுத்தினீர்கள். வணக்கம்!")
|
| 353 |
+
sys.exit(0)
|