YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
chore: small optim
Louis Beaumont97fc2fcd7ed9
diff --git a/screenpipe-server/src/bin/screenpipe-server.rs b/screenpipe-server/src/bin/screenpipe-server.rsindex f18707988..789e9896f 100644--- a/screenpipe-server/src/bin/screenpipe-server.rs+++ b/screenpipe-server/src/bin/screenpipe-server.rs@@ -5,6 +5,7 @@ use std::{};use clap::Parser;+use log::info;use tokio::time::Duration;use screenpipe_server::{start_continuous_recording, DatabaseManager, Server};@@ -74,7 +75,7 @@ async fn main() -> anyhow::Result<()> {});// Wait for the server to start- println!("Server started on http://localhost:{}", cli.port);+ info!("Server started on http://localhost:{}", cli.port);// Keep the main thread runningloop {diff --git a/screenpipe-vision/src/core.rs b/screenpipe-vision/src/core.rsindex e48b0d747..e4b6ac9aa 100644--- a/screenpipe-vision/src/core.rs+++ b/screenpipe-vision/src/core.rs@@ -4,11 +4,14 @@ use rusty_tesseract::{Args, Image};use threadpool::ThreadPool;use xcap::Monitor;+use std::collections::HashMap;+use std::hash::DefaultHasher;+use std::hash::Hash;+use std::hash::Hasher;use std::sync::mpsc::{Receiver, Sender};use std::sync::{Arc, Mutex};use std::thread;use std::time::Duration;-pub enum ControlMessage {Pause,Resume,@@ -38,6 +41,7 @@ pub fn continuous_capture(let ocr_pool = ThreadPool::new(pool_size);let is_paused = Arc::new(Mutex::new(false));let should_stop = Arc::new(Mutex::new(false));+ let cache = Arc::new(Mutex::new(HashMap::<u64, String>::new()));loop {// Check for control messagesif let Ok(message) = control_rx.try_recv() {@@ -60,12 +64,25 @@ pub fn continuous_capture(let buffer = monitor.capture_image().unwrap();let image = DynamicImage::ImageRgba8(buffer);+ // Generate hash for the image+ let image_hash = calculate_hash(&image);+// Clone necessary values for the OCR threadlet result_tx_clone = result_tx.clone();let image_arc = Arc::new(image);+ let cache_clone = Arc::clone(&cache);+// Perform OCR in a separate threadocr_pool.execute(move || {- let text = perform_ocr(&image_arc);+ let mut cache = cache_clone.lock().unwrap();+ let text = if let Some(cached_text) = cache.get(&image_hash) {+ cached_text.clone()+ } else {+ let new_text = perform_ocr(&image_arc);+ cache.insert(image_hash, new_text.clone());+ new_text+ };+result_tx_clone.send(CaptureResult {image: image_arc,@@ -84,6 +101,12 @@ pub fn continuous_capture(ocr_pool.join();}+fn calculate_hash(image: &DynamicImage) -> u64 {+ let mut hasher = DefaultHasher::new();+ image.as_bytes().hash(&mut hasher);+ hasher.finish()+}+fn perform_ocr(image: &DynamicImage) -> String {let args = Args::default();let ocr_image = Image::from_dynamic_image(image).unwrap();