Spaces:
Running
Running
TeleologyHI
commited on
Commit
·
dde614e
1
Parent(s):
70f8d75
Update HIM implementation with consciousness framework
Browse files- app.py +13 -10
- src/core/consciousness_kernel.py +3 -16
- src/model/him_model.py +13 -2
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from src.model.him_model import HIMModel
|
3 |
from config.model_config import HIMConfig
|
4 |
from config.environment_config import EnvironmentConfig
|
@@ -6,15 +7,16 @@ from config.environment_config import EnvironmentConfig
|
|
6 |
def initialize_model():
|
7 |
model_config = HIMConfig()
|
8 |
env_config = EnvironmentConfig()
|
9 |
-
|
|
|
|
|
10 |
|
11 |
-
def chat(
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
):
|
18 |
input_data = {
|
19 |
"message": message,
|
20 |
"system_message": system_message,
|
@@ -25,7 +27,8 @@ def chat(
|
|
25 |
}
|
26 |
}
|
27 |
|
28 |
-
|
|
|
29 |
return result["response"]
|
30 |
|
31 |
model = initialize_model()
|
@@ -49,5 +52,5 @@ if __name__ == "__main__":
|
|
49 |
interface.launch(
|
50 |
server_name=env_config.api_host,
|
51 |
server_port=env_config.api_port,
|
52 |
-
|
53 |
)
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
from src.model.him_model import HIMModel
|
4 |
from config.model_config import HIMConfig
|
5 |
from config.environment_config import EnvironmentConfig
|
|
|
7 |
def initialize_model():
|
8 |
model_config = HIMConfig()
|
9 |
env_config = EnvironmentConfig()
|
10 |
+
device = torch.device("cuda" if torch.cuda.is_available() and env_config.device == "cuda" else "cpu")
|
11 |
+
model = HIMModel(model_config).to(device)
|
12 |
+
return model
|
13 |
|
14 |
+
def chat(message: str,
|
15 |
+
system_message: str = "You are a friendly Chatbot.",
|
16 |
+
max_tokens: int = 512,
|
17 |
+
temperature: float = 0.7,
|
18 |
+
top_p: float = 0.95):
|
19 |
+
|
|
|
20 |
input_data = {
|
21 |
"message": message,
|
22 |
"system_message": system_message,
|
|
|
27 |
}
|
28 |
}
|
29 |
|
30 |
+
with torch.no_grad():
|
31 |
+
result = model.generate_response(input_data)
|
32 |
return result["response"]
|
33 |
|
34 |
model = initialize_model()
|
|
|
52 |
interface.launch(
|
53 |
server_name=env_config.api_host,
|
54 |
server_port=env_config.api_port,
|
55 |
+
share=True
|
56 |
)
|
src/core/consciousness_kernel.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
from dataclasses import dataclass
|
2 |
from enum import Enum
|
3 |
import torch
|
|
|
4 |
import numpy as np
|
5 |
-
from typing import Dict, List, Optional
|
|
|
6 |
|
7 |
@dataclass
|
8 |
class ConsciousnessState:
|
@@ -19,10 +21,6 @@ class ConsciousnessLevel(Enum):
|
|
19 |
REFLECTIVE = "reflective_consciousness"
|
20 |
INTEGRATED = "integrated_consciousness"
|
21 |
|
22 |
-
from typing import Dict, List, Any
|
23 |
-
import asyncio
|
24 |
-
import torch
|
25 |
-
|
26 |
class ConsciousnessKernel:
|
27 |
def __init__(self):
|
28 |
self.awareness_module = nn.Sequential(
|
@@ -32,17 +30,6 @@ class ConsciousnessKernel:
|
|
32 |
)
|
33 |
self.integration_module = nn.Linear(256, 128)
|
34 |
self.state_history = []
|
35 |
-
|
36 |
-
def process_consciousness_cycle(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
37 |
-
awareness_state = self._process_awareness(input_data)
|
38 |
-
integrated_state = self._integrate_information(awareness_state)
|
39 |
-
self._update_history(integrated_state)
|
40 |
-
|
41 |
-
return {
|
42 |
-
'current_state': integrated_state,
|
43 |
-
'awareness_level': self._calculate_awareness_level(integrated_state),
|
44 |
-
'consciousness_metrics': self._compute_phi_metrics(integrated_state)
|
45 |
-
}
|
46 |
self.awareness_engine = AwarenessEngine()
|
47 |
self.integration_manager = IntegrationManager()
|
48 |
self.self_model = DynamicSelfModel()
|
|
|
1 |
from dataclasses import dataclass
|
2 |
from enum import Enum
|
3 |
import torch
|
4 |
+
import torch.nn as nn
|
5 |
import numpy as np
|
6 |
+
from typing import Dict, List, Optional, Any
|
7 |
+
import asyncio
|
8 |
|
9 |
@dataclass
|
10 |
class ConsciousnessState:
|
|
|
21 |
REFLECTIVE = "reflective_consciousness"
|
22 |
INTEGRATED = "integrated_consciousness"
|
23 |
|
|
|
|
|
|
|
|
|
24 |
class ConsciousnessKernel:
|
25 |
def __init__(self):
|
26 |
self.awareness_module = nn.Sequential(
|
|
|
30 |
)
|
31 |
self.integration_module = nn.Linear(256, 128)
|
32 |
self.state_history = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
self.awareness_engine = AwarenessEngine()
|
34 |
self.integration_manager = IntegrationManager()
|
35 |
self.self_model = DynamicSelfModel()
|
src/model/him_model.py
CHANGED
@@ -9,12 +9,13 @@ from ..core.semiotic_processor import SemioticProcessor
|
|
9 |
class HIMModel(nn.Module):
|
10 |
def __init__(self, config: Dict[str, Any]):
|
11 |
super().__init__()
|
|
|
12 |
self.consciousness_kernel = ConsciousnessKernel()
|
13 |
self.emotional_processor = EmotionalProcessor()
|
14 |
self.theory_of_mind = TheoryOfMind()
|
15 |
self.semiotic_processor = SemioticProcessor()
|
16 |
|
17 |
-
def
|
18 |
consciousness_state = self.consciousness_kernel.process_consciousness_cycle(input_data)
|
19 |
emotional_context = self.emotional_processor.process_emotional_context(input_data)
|
20 |
social_understanding = self.theory_of_mind.model_agent_mind(input_data)
|
@@ -25,4 +26,14 @@ class HIMModel(nn.Module):
|
|
25 |
emotional_context,
|
26 |
social_understanding,
|
27 |
semiotic_analysis
|
28 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
class HIMModel(nn.Module):
|
10 |
def __init__(self, config: Dict[str, Any]):
|
11 |
super().__init__()
|
12 |
+
self.config = config
|
13 |
self.consciousness_kernel = ConsciousnessKernel()
|
14 |
self.emotional_processor = EmotionalProcessor()
|
15 |
self.theory_of_mind = TheoryOfMind()
|
16 |
self.semiotic_processor = SemioticProcessor()
|
17 |
|
18 |
+
def generate_response(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
|
19 |
consciousness_state = self.consciousness_kernel.process_consciousness_cycle(input_data)
|
20 |
emotional_context = self.emotional_processor.process_emotional_context(input_data)
|
21 |
social_understanding = self.theory_of_mind.model_agent_mind(input_data)
|
|
|
26 |
emotional_context,
|
27 |
social_understanding,
|
28 |
semiotic_analysis
|
29 |
+
)
|
30 |
+
|
31 |
+
def _integrate_outputs(self, *states) -> Dict[str, Any]:
|
32 |
+
# Integration implementation
|
33 |
+
return {
|
34 |
+
"response": "Integrated response based on multiple processing layers",
|
35 |
+
"consciousness_state": states[0],
|
36 |
+
"emotional_context": states[1],
|
37 |
+
"social_understanding": states[2],
|
38 |
+
"semiotic_analysis": states[3]
|
39 |
+
}
|