summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbdellah El Morabit <nsrddyn@gmail.com>2024-11-14 19:31:03 +0100
committerAbdellah El Morabit <nsrddyn@gmail.com>2024-11-14 19:31:03 +0100
commitfe441f69a4632e5245588574923ef8dc467eced5 (patch)
treec9975c3b706a4c810ba975c2884c748d7255c770
parent9ebcbfc83a64b8a27d0725dbd12f6a8fdb042934 (diff)
tried implementing ollama
-rw-r--r--I2C/I2C.xcodeproj/project.xcworkspace/xcuserdata/nsrddyn.xcuserdatad/UserInterfaceState.xcuserstatebin28421 -> 37489 bytes
-rw-r--r--I2C/I2C.xcodeproj/xcuserdata/nsrddyn.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist40
-rw-r--r--I2C/I2C/ContentView.swift27
-rw-r--r--I2C/I2CUITests/I2CUITests.swift1
-rw-r--r--bin/__pycache__/source.cpython-313.pycbin0 -> 5737 bytes
-rw-r--r--bin/i2c.py47
-rw-r--r--bin/icon.pngbin3754 -> 0 bytes
-rw-r--r--bin/kasper_gui.py6
-rw-r--r--bin/kasper_source.py154
-rw-r--r--bin/main.py9
-rw-r--r--bin/source.py128
-rw-r--r--webconsole/index.html12
-rw-r--r--webconsole/main.js0
13 files changed, 241 insertions, 183 deletions
diff --git a/I2C/I2C.xcodeproj/project.xcworkspace/xcuserdata/nsrddyn.xcuserdatad/UserInterfaceState.xcuserstate b/I2C/I2C.xcodeproj/project.xcworkspace/xcuserdata/nsrddyn.xcuserdatad/UserInterfaceState.xcuserstate
index 78be191..07340b1 100644
--- a/I2C/I2C.xcodeproj/project.xcworkspace/xcuserdata/nsrddyn.xcuserdatad/UserInterfaceState.xcuserstate
+++ b/I2C/I2C.xcodeproj/project.xcworkspace/xcuserdata/nsrddyn.xcuserdatad/UserInterfaceState.xcuserstate
Binary files differ
diff --git a/I2C/I2C.xcodeproj/xcuserdata/nsrddyn.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/I2C/I2C.xcodeproj/xcuserdata/nsrddyn.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
new file mode 100644
index 0000000..214cbf9
--- /dev/null
+++ b/I2C/I2C.xcodeproj/xcuserdata/nsrddyn.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Bucket
+ uuid = "E25B4326-8E67-45A7-85E6-44F99F067B3F"
+ type = "1"
+ version = "2.0">
+ <Breakpoints>
+ <BreakpointProxy
+ BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+ <BreakpointContent
+ uuid = "CDFF4D12-343E-452F-9711-F46A454AB787"
+ shouldBeEnabled = "Yes"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ filePath = "I2C/ContentView.swift"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "12"
+ endingLineNumber = "12"
+ landmarkName = "body"
+ landmarkType = "24">
+ </BreakpointContent>
+ </BreakpointProxy>
+ <BreakpointProxy
+ BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+ <BreakpointContent
+ uuid = "D2C0A7B9-3CCF-4EDE-B649-263CFF06097B"
+ shouldBeEnabled = "Yes"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ filePath = "I2CUITests/I2CUITests.swift"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "19"
+ endingLineNumber = "19"
+ landmarkName = "I2CUITests"
+ landmarkType = "3">
+ </BreakpointContent>
+ </BreakpointProxy>
+ </Breakpoints>
+</Bucket>
diff --git a/I2C/I2C/ContentView.swift b/I2C/I2C/ContentView.swift
index e21bcb2..6d0448d 100644
--- a/I2C/I2C/ContentView.swift
+++ b/I2C/I2C/ContentView.swift
@@ -1,34 +1,17 @@
import SwiftUI
struct ContentView: View {
- var header: some View {
- VStack {
- Text("Hello world!")
- }
-
- }
+ let options = ["CPU INFO", "CPU UPTIME", "SPEECH TRANSCRIBER", "NOTES"]
var body: some View {
VStack {
- Circle()
- .fill(.blue)
- .frame(width: 100, height: 100)
- .padding()
- header
- Button("VOICE RECOGNITION"){
-
- }
- Button("CPU UPTIME"){
-
- }
- Button("CPU INFO"){
-
- }
+ Button(
+ RoundedRectangle(cornerRadius: 25)
+ .fill(Color.red)
+ )
}
}
}
-
-
#Preview {
ContentView()
}
diff --git a/I2C/I2CUITests/I2CUITests.swift b/I2C/I2CUITests/I2CUITests.swift
index c225d79..a98bb08 100644
--- a/I2C/I2CUITests/I2CUITests.swift
+++ b/I2C/I2CUITests/I2CUITests.swift
@@ -3,7 +3,6 @@
// I2CUITests
//
// Created by nsrddyn on 09/11/2024.
-//
import XCTest
diff --git a/bin/__pycache__/source.cpython-313.pyc b/bin/__pycache__/source.cpython-313.pyc
new file mode 100644
index 0000000..79aee1d
--- /dev/null
+++ b/bin/__pycache__/source.cpython-313.pyc
Binary files differ
diff --git a/bin/i2c.py b/bin/i2c.py
new file mode 100644
index 0000000..a79d9d1
--- /dev/null
+++ b/bin/i2c.py
@@ -0,0 +1,47 @@
+import smbus2 as SMBus
+import time
+
+LCD_BACKLIGHT = 0x08
+LCD_NOBACKLIGHT = 0x00
+ENABLE_BIT = 0b00000100
+LINES = {1: 0x80, 2: 0xC0}
+ALIGN_FUNC = {"left": "ljust", "right": "rjust", "center": "center"}
+
+
+class LCD:
+
+ def __init__(self, address=0x27, bus=1, width=20, rows=4, backlight=True):
+ self.address = address
+ self.bus = SMBus(bus)
+ self.width = width
+ self.rows = rows
+ self.backlight_status = backlight
+ self.delay = 0.0005
+
+ for cmd in (0x33, 0x32, 0x06, 0x0C, 0x28, 0x01):
+ self.write(cmd)
+ time.sleep(self.delay)
+
+ def write(self, byte, mode=0):
+ backlight = LCD_BACKLIGHT if self.backlight_status else LCD_NOBACKLIGHT
+ self._write_byte(mode | ((byte << 4) & 0xF0) | backlight)
+
+ def _write_byte(self, byte):
+ self.bus.write_byte(self.address, byte)
+ self.bus.write_byte(self.address, (byte | ENABLE_BIT))
+ time.sleep(self.delay)
+ self.bus.write_byte(self.address, (byte & ~ENABLE_BIT))
+ time.sleep(self.delay)
+
+ def display_text(self, text, line=1, align="left"):
+ self.write(LINES.get(line, LINES[1]))
+ aligned_text = getattr(text, ALIGN_FUNC.get(align, "ljust"))(self.width)
+ for char in aligned_text:
+ self.write(ord(char), mode=1)
+
+ def clear(self):
+ self.write(0x01)
+
+ def set_backlight(self, turn_on=True):
+ self.backlight_status = turn_on
+ self.write(0)
diff --git a/bin/icon.png b/bin/icon.png
deleted file mode 100644
index c372c49..0000000
--- a/bin/icon.png
+++ /dev/null
Binary files differ
diff --git a/bin/kasper_gui.py b/bin/kasper_gui.py
deleted file mode 100644
index e5edc6a..0000000
--- a/bin/kasper_gui.py
+++ /dev/null
@@ -1,6 +0,0 @@
-import tkinter
-
-display = tkinter.Tk()
-display.title("Kasper")
-
-display.mainloop() \ No newline at end of file
diff --git a/bin/kasper_source.py b/bin/kasper_source.py
deleted file mode 100644
index 8067997..0000000
--- a/bin/kasper_source.py
+++ /dev/null
@@ -1,154 +0,0 @@
-from smbus import SMBus
-from gpiozero import CPUTemperature
-import speech_recognition as speech
-import os
-import time
-from time import sleep
-
-# LCD Constants
-LCD_BACKLIGHT = 0x08
-LCD_NOBACKLIGHT = 0x00
-ENABLE_BIT = 0b00000100
-LINES = {1: 0x80, 2: 0xC0, 3: 0x94, 4: 0xD4}
-ALIGN_FUNC = {"left": "ljust", "right": "rjust", "center": "center"}
-
-# Error Messages
-ERROR_BAD_REQUEST = "400 Bad Request"
-ERROR_UNAUTHORIZED = "401 Unauthorized"
-ERROR_NOT_FOUND = "404 Not Found"
-ERROR_TIMEOUT = "408 Request Timeout"
-
-# LCD Control Class
-class LCD:
-
- def __init__(self, address=0x27, bus=1, width=20, rows=4, backlight=True):
- self.address = address
- self.bus = SMBus(bus)
- self.width = width
- self.rows = rows
- self.backlight_status = backlight
- self.delay = 0.0005
-
- # LCD Initialization
- for cmd in (0x33, 0x32, 0x06, 0x0C, 0x28, 0x01):
- self.write(cmd)
- time.sleep(self.delay)
-
- def write(self, byte, mode=0):
- """Send a command or character to the LCD."""
- backlight = LCD_BACKLIGHT if self.backlight_status else LCD_NOBACKLIGHT
- self._write_byte(mode | ((byte << 4) & 0xF0) | backlight)
-
- def _write_byte(self, byte):
- """Write a byte to the I2C bus."""
- self.bus.write_byte(self.address, byte)
- self.bus.write_byte(self.address, (byte | ENABLE_BIT))
- time.sleep(self.delay)
- self.bus.write_byte(self.address, (byte & ~ENABLE_BIT))
- time.sleep(self.delay)
-
- def display_text(self, text, line=1, align="left"):
- """Display text on a specified line with alignment."""
- self.write(LINES.get(line, LINES[1]))
- aligned_text = getattr(text, ALIGN_FUNC.get(align, "ljust"))(self.width)
- for char in aligned_text:
- self.write(ord(char), mode=1)
-
- def clear(self):
- """Clear the display."""
- self.write(0x01)
-
- def set_backlight(self, turn_on=True):
- """Toggle backlight on or off."""
- self.backlight_status = turn_on
- self.write(0)
-
-# Initialize components
-lcd = LCD()
-cpu_temp = CPUTemperature()
-recognizer = speech.Recognizer()
-microphone = speech.Microphone()
-
-
-# Display Functions
-def display_cpu_info():
- # clearing the display before accessing it
- lcd.clear()
- """Display CPU load and temperature on the LCD."""
- while True:
- load = os.getloadavg()[0] # 1-minute load average
- temperature = cpu_temp.temperature
- lcd.clear()
- lcd.display_text(f"CPU Load: {load:.2f}", 1)
- lcd.display_text(f"Temp: {temperature:.1f}C", 2)
- time.sleep(5)
-
-
-def display_uptime():
- # clearing the display before accessing it
- lcd.clear()
- """Display system uptime on the LCD."""
- with open("/proc/uptime") as f:
- uptime_seconds = float(f.readline().split()[0])
- uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds))
- lcd.clear()
- lcd.display_text(f"Uptime: {uptime_str}", 1)
-
-
-def recognize_speech():
- # clearing the display before accessing it
- lcd.clear()
- """Capture and transcribe speech input."""
- try:
- with microphone as source:
- recognizer.adjust_for_ambient_noise(source)
- print("Listening...")
- audio = recognizer.listen(source)
- text = recognizer.recognize_google(audio)
- lcd.clear()
- lcd.display_text(text, 1)
- print("Speech recognized:", text)
- except speech.UnknownValueError:
- lcd.display_text(ERROR_BAD_REQUEST, 1)
- print(ERROR_BAD_REQUEST)
- except speech.RequestError:
- lcd.display_text(ERROR_UNAUTHORIZED, 1)
- print(ERROR_UNAUTHORIZED)
-
-def notes():
- while True:
- OUTPUT = input()
- print(OUTPUT)
- lcd.display_text(OUTPUT, 1)
- sleep(2)
-
-
-# Main Program Options
-OPTIONS = {
- "CPU_INFO": display_cpu_info,
- "UPTIME": display_uptime,
- "SPEECH_TRANSCRIBER": recognize_speech,
- "NOTES": notes,
-}
-
-
-def main():
- # clearing the display before doing anything
- lcd.clear()
- # Main program loop to accept user commands.
- print("WELCOME TO THE I2C COMMAND LINE CENTER")
- print("Options:", ", ".join(OPTIONS.keys()))
-
- while True:
- user_input = input("Enter command: ").upper()
- action = OPTIONS.get(user_input)
-
- if action:
- action()
- else:
- lcd.display_text(ERROR_NOT_FOUND, 1)
- print(ERROR_NOT_FOUND)
-
-
-if __name__ == "__main__":
- main()
diff --git a/bin/main.py b/bin/main.py
new file mode 100644
index 0000000..2231547
--- /dev/null
+++ b/bin/main.py
@@ -0,0 +1,9 @@
+import tk
+import source as main
+
+source = main()
+
+display = tk.Tk()
+display.title("Kasper")
+
+display.mainloop() \ No newline at end of file
diff --git a/bin/source.py b/bin/source.py
new file mode 100644
index 0000000..c232351
--- /dev/null
+++ b/bin/source.py
@@ -0,0 +1,128 @@
+import time
+import os
+import ollama
+import speech_recognition as speech
+import i2c as LCD
+from gpiozero import CPUTemperature
+
+ERROR_BAD_REQUEST = "400 Bad Request"
+ERROR_UNAUTHORIZED = "401 Unauthorized"
+ERROR_NOT_FOUND = "404 Not Found"
+ERROR_TIMEOUT = "408 Request Timeout"
+
+lcd = LCD()
+cpu_temp = CPUTemperature()
+lama = ollama()
+recognizer = speech.Recognizer()
+microphone = speech.Microphone()
+
+
+def display_cpu_info():
+ lcd.clear()
+ while True:
+ load = os.getloadavg()[0] # 1-minute load average
+ temperature = cpu_temp.temperature
+ lcd.clear()
+ lcd.display_text(f"CPU Load:i {load}", 1)
+ lcd.display_text(f"Temp: {temperature:}C", 2)
+ time.sleep(5)
+
+
+def display_uptime():
+ lcd.clear()
+ with open("/proc/uptime") as f:
+ uptime_seconds = float(f.readline().split()[0])
+ uptime_str = time.strftime("%H:%M:%S", time.gmtime(uptime_seconds))
+ lcd.clear()
+ lcd.display_text(f"Uptime: {uptime_str}", 1, "center")
+
+
+def recognize_speech():
+ lcd.clear()
+ try:
+ with microphone as source:
+ recognizer.adjust_for_ambient_noise(source)
+ print("Listening...")
+ audio = recognizer.listen(source)
+ text = recognizer.recognize_google(audio)
+ lcd.clear()
+ lcd.display_text(text, 1)
+ print("Speech recognized:", text)
+ except speech.UnknownValueError:
+ lcd.display_text(ERROR_BAD_REQUEST, 1)
+ print(ERROR_BAD_REQUEST)
+ except speech.RequestError:
+ lcd.display_text(ERROR_UNAUTHORIZED, 1)
+ print(ERROR_UNAUTHORIZED)
+
+
+def save_notes():
+ PRINT_REQUEST = True
+ EXIT_CODES = ['stop', 'break', 'quit', 'exit']
+ if PRINT_REQUEST == True:
+ while True:
+ OUTPUT = input()
+ print(OUTPUT)
+ lcd.display_text(OUTPUT, 1)
+ time.sleep(2)
+ for i in EXIT_CODES:
+ if OUTPUT == i:
+ PRINT_REQUEST == False
+
+def lama():
+ QUESTION_REQUEST = True
+ while QUESTION_REQUEST == True:
+ QUESTION_REQUEST = input
+ ("do you want to ask a question") == 'yes'
+ if QUESTION_REQUEST == True:
+ USER_QUESTION = input()
+ response = lama.chat(
+ model="llama3.2",
+ messages=[
+ {
+ "role": "user",
+ "content": USER_QUESTION,
+ },
+ ],
+ )
+ print(response["messages"]["content"])
+ else:
+ break
+
+
+
+OPTIONS = {
+ "LAMA": ollama(),
+ "CPU_INFO": display_cpu_info(),
+ "UPTIME": display_uptime(),
+ "SPEECH_TRANSCRIBER": recognize_speech(),
+ "NOTES": save_notes(),
+}
+
+
+def main():
+ lcd.clear()
+ print("WELCOME TO THE I2C COMMAND LINE CENTER")
+ print("Options:", ", ".join(OPTIONS.keys()))
+
+ while True:
+ user_input = input("Enter command: ").upper()
+ action = OPTIONS.get(user_input)
+
+ if action:
+ action()
+ else:
+ lcd.display_text(ERROR_NOT_FOUND, 1)
+ print(ERROR_NOT_FOUND)
+
+
+def destroy():
+ lcd.clear()
+ os.system("cls" if os.name == "nt" else "clear")
+
+
+if __name__ == "__main__":
+ try:
+ main()
+ except KeyboardInterrupt:
+ destroy()
diff --git a/webconsole/index.html b/webconsole/index.html
new file mode 100644
index 0000000..812011f
--- /dev/null
+++ b/webconsole/index.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>CONSOLE</title>
+</head>
+<body>
+
+
+</body>
+</html> \ No newline at end of file
diff --git a/webconsole/main.js b/webconsole/main.js
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/webconsole/main.js