dauksza123 commited on
Commit
1b3d576
·
verified ·
1 Parent(s): 93ddcb2

Upload 2 files

Browse files
Files changed (2) hide show
  1. StarReliabilityApp_Refined.py +132 -0
  2. central_data.db +0 -0
StarReliabilityApp_Refined.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import sys
3
+ import sqlite3
4
+ import requests
5
+ from PyQt5 import QtWidgets, QtCore
6
+ import pyttsx3 # For TTS
7
+ import speech_recognition as sr # For STT
8
+
9
+ # Initialize the Ollama API URL and TTS Engine
10
+ OLLAMA_API_URL = "http://127.0.0.1:11434/api/generate"
11
+ tts_engine = pyttsx3.init()
12
+
13
+ class CentralAI:
14
+ def __init__(self, db_path):
15
+ self.connection = sqlite3.connect(db_path)
16
+ self.short_term_memory = []
17
+ self.medium_term_memory = []
18
+ self.long_term_memory = {}
19
+ self.load_long_term_memory()
20
+
21
+ def load_long_term_memory(self):
22
+ cursor = self.connection.cursor()
23
+ cursor.execute("SELECT key, value FROM long_term_memory")
24
+ self.long_term_memory = {row[0]: row[1] for row in cursor.fetchall()}
25
+
26
+ def process_user_input(self, user_input):
27
+ # Step 1: Process - Use NLU to interpret the user input
28
+ prompt = self.fetch_prompt("Process")
29
+ processed_intent = self.nlp_parse(user_input, prompt)
30
+
31
+ # Step 2: Find - Reference `central_data.db` for required info
32
+ query_data = self.find_data(processed_intent)
33
+
34
+ # Step 3: Execute - Run functions based on user intent
35
+ action_response = self.execute_function(query_data)
36
+
37
+ # Send to Ollama API for final response
38
+ final_response = self.generate_response_via_ollama(user_input, action_response)
39
+ return final_response
40
+
41
+ def fetch_prompt(self, prompt_name):
42
+ cursor = self.connection.cursor()
43
+ cursor.execute("SELECT description FROM prompts WHERE title = ?", (prompt_name,))
44
+ result = cursor.fetchone()
45
+ return result[0] if result else ""
46
+
47
+ def nlp_parse(self, text, prompt):
48
+ # Mimic processing with the prompt and return an interpreted command.
49
+ return f"Interpreted Command: {text} with prompt context: {prompt}"
50
+
51
+ def find_data(self, intent):
52
+ # Sample code for fetching related database data
53
+ cursor = self.connection.cursor()
54
+ cursor.execute("SELECT * FROM functions WHERE function_name = ?", (intent,))
55
+ return cursor.fetchone()
56
+
57
+ def execute_function(self, function_data):
58
+ # Example execution response, this would normally invoke the function
59
+ return f"Executing: {function_data}"
60
+
61
+ def generate_response_via_ollama(self, user_input, action_response):
62
+ response = requests.post(OLLAMA_API_URL, json={"prompt": f"{user_input}\n{action_response}"})
63
+ return response.json().get("response", "Error generating response.")
64
+
65
+ def update_memory(self, memory_type, content):
66
+ # Manage short, medium, and long term memory
67
+ if memory_type == "short_term":
68
+ self.short_term_memory.append(content)
69
+ elif memory_type == "medium_term":
70
+ self.medium_term_memory.append(content)
71
+ elif memory_type == "long_term":
72
+ self.long_term_memory.update(content)
73
+
74
+ class StarReliabilityApp(QtWidgets.QMainWindow):
75
+ def __init__(self):
76
+ super().__init__()
77
+ self.setWindowTitle("StarReliability Maintenance Dashboard")
78
+ self.setGeometry(100, 100, 1200, 800)
79
+ self.central_ai = CentralAI("central_data.db")
80
+ self.initUI()
81
+
82
+ def initUI(self):
83
+ # Dashboard setup with chat and widgets for metrics, budget, etc.
84
+ self.chat_output = QtWidgets.QTextEdit()
85
+ self.chat_input = QtWidgets.QLineEdit()
86
+ self.chat_input.returnPressed.connect(self.process_chat_input)
87
+
88
+ self.chat_output.setReadOnly(True)
89
+ self.chat_input.setPlaceholderText("Type a message or speak...")
90
+
91
+ layout = QtWidgets.QVBoxLayout()
92
+ layout.addWidget(self.chat_output)
93
+ layout.addWidget(self.chat_input)
94
+
95
+ container = QtWidgets.QWidget()
96
+ container.setLayout(layout)
97
+ self.setCentralWidget(container)
98
+
99
+ def process_chat_input(self):
100
+ user_input = self.chat_input.text()
101
+ self.chat_output.append(f"User: {user_input}")
102
+ response = self.central_ai.process_user_input(user_input)
103
+ self.chat_output.append(f"AI: {response}")
104
+ self.chat_input.clear()
105
+ self.speak_response(response)
106
+
107
+ def speak_response(self, response):
108
+ tts_engine.say(response)
109
+ tts_engine.runAndWait()
110
+
111
+ def voice_input(self):
112
+ recognizer = sr.Recognizer()
113
+ with sr.Microphone() as source:
114
+ self.chat_output.append("Listening for command...")
115
+ audio = recognizer.listen(source)
116
+ try:
117
+ user_input = recognizer.recognize_google(audio)
118
+ self.chat_input.setText(user_input)
119
+ self.process_chat_input()
120
+ except sr.UnknownValueError:
121
+ self.chat_output.append("Could not understand audio.")
122
+ except sr.RequestError:
123
+ self.chat_output.append("STT service unavailable.")
124
+
125
+ def run_app():
126
+ app = QtWidgets.QApplication(sys.argv)
127
+ main_window = StarReliabilityApp()
128
+ main_window.show()
129
+ sys.exit(app.exec_())
130
+
131
+ if __name__ == "__main__":
132
+ run_app()
central_data.db ADDED
Binary file (131 kB). View file