Capstone / agents /neural_network_agent.py
prabalGaur's picture
Fix Path import in neural network agents
845dc86 verified
Raw
History Blame Contribute Delete
1.33 kB
from pathlib import Path
from agents.agent import Agent
from agents.deep_neural_network import DeepNeuralNetworkInference
WEIGHTS_PATH = Path("deep_neural_network.pth")
class NeuralNetworkAgent(Agent):
name = "Neural Network Agent"
color = Agent.MAGENTA
def __init__(self):
self.neural_network = None
self.log("Neural Network Agent is initializing")
if not WEIGHTS_PATH.exists():
self.log(
"Neural network weights not found (deep_neural_network.pth) — agent disabled. "
"Fine for Hugging Face Spaces under 1GB storage limit."
)
return
self.neural_network = DeepNeuralNetworkInference()
self.neural_network.setup()
self.neural_network.load(str(WEIGHTS_PATH))
self.log("Neural Network Agent is ready and weights are loaded")
@property
def available(self) -> bool:
return self.neural_network is not None
def price(self, description: str) -> float:
if not self.available:
return 0.0
self.log("Neural Network Agent is starting a prediction")
result = self.neural_network.inference(description)
self.log(f"Neural Network Agent completed - predicting ${result:.2f}")
return result