Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -21,17 +21,43 @@ class CognitiveNetworkDemo:
|
|
21 |
))
|
22 |
|
23 |
# Add model directory to Python path
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
def load_model(self):
|
28 |
"""Load the model if not already loaded"""
|
29 |
if self.model is None:
|
30 |
try:
|
31 |
-
#
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
self.model = DynamicCognitiveNet(input_size=5, output_size=2)
|
|
|
34 |
except ImportError as e:
|
|
|
35 |
raise ImportError(f"Gagal mengimpor model: {str(e)}")
|
36 |
return self.model
|
37 |
|
@@ -58,7 +84,7 @@ class CognitiveNetworkDemo:
|
|
58 |
except ValueError as e:
|
59 |
return f"Error dalam format input: {str(e)}"
|
60 |
except Exception as e:
|
61 |
-
return f"Error: {str(e)}"
|
62 |
|
63 |
def main():
|
64 |
# Initialize the demo
|
|
|
21 |
))
|
22 |
|
23 |
# Add model directory to Python path
|
24 |
+
model_dir = self.repo_path
|
25 |
+
if str(model_dir) not in sys.path:
|
26 |
+
sys.path.insert(0, str(model_dir))
|
27 |
+
|
28 |
+
# Print directory contents for debugging
|
29 |
+
print("Repository contents:")
|
30 |
+
for path in model_dir.rglob("*"):
|
31 |
+
print(f" {path.relative_to(model_dir)}")
|
32 |
|
33 |
def load_model(self):
|
34 |
"""Load the model if not already loaded"""
|
35 |
if self.model is None:
|
36 |
try:
|
37 |
+
# Try different import paths
|
38 |
+
try:
|
39 |
+
from network import DynamicCognitiveNet
|
40 |
+
except ImportError:
|
41 |
+
try:
|
42 |
+
from cognitive_net.network import DynamicCognitiveNet
|
43 |
+
except ImportError:
|
44 |
+
# Search for the network.py file
|
45 |
+
network_files = list(self.repo_path.rglob("network.py"))
|
46 |
+
if not network_files:
|
47 |
+
raise ImportError("Tidak dapat menemukan file network.py")
|
48 |
+
|
49 |
+
# Add the parent directory of the first found network.py to path
|
50 |
+
network_dir = network_files[0].parent
|
51 |
+
if str(network_dir) not in sys.path:
|
52 |
+
sys.path.insert(0, str(network_dir))
|
53 |
+
|
54 |
+
# Try import again
|
55 |
+
from network import DynamicCognitiveNet
|
56 |
+
|
57 |
self.model = DynamicCognitiveNet(input_size=5, output_size=2)
|
58 |
+
|
59 |
except ImportError as e:
|
60 |
+
print("Debug - sys.path:", sys.path)
|
61 |
raise ImportError(f"Gagal mengimpor model: {str(e)}")
|
62 |
return self.model
|
63 |
|
|
|
84 |
except ValueError as e:
|
85 |
return f"Error dalam format input: {str(e)}"
|
86 |
except Exception as e:
|
87 |
+
return f"Error: {str(e)}\n\nDebug info:\nRepo path: {self.repo_path}"
|
88 |
|
89 |
def main():
|
90 |
# Initialize the demo
|