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
feat: add OCR feature
Louis Beaumont4b8b9d9cce94
diff --git a/.gitignore b/.gitignoreindex f86f4ad1e..b299c0292 100644--- a/.gitignore+++ b/.gitignore@@ -15,4 +15,11 @@# IDE specific files.idea/.vscode/-*.rs.bk\ No newline at end of file+*.rs.bk++++# todo remove these when deleted python dirty stuff+env+__pycache__+diff --git a/README.md b/README.mdindex 1aa4b7be3..47f6fd4fb 100644--- a/README.md+++ b/README.md@@ -45,33 +45,44 @@ export async function onTick() {}```-## On your computer-To start capturing screen data and send it to a specific storage location such as Amazon S3, use the following command line interface (CLI) command:+## Status-```bash-screenpipe --path ./second-memory-```+Alpha: runs on my computer. Capture things and do things.-https://github.com/louis030195/screen-pipe/assets/25003283/08a8c9d6-0be6-44c2-b37f-62d0721fe8c3+## Usage+Keep in mind that it's still experimental but got a working prototype, see the [Related projects](#related-projects) section.+To try the current version, which capture your screen and extract the text, run:-## Status+```bash+git clone https://github.com/louis030195/screen-pipe+cd screen-pipe+```-Alpha: runs on my computer. Capture things and do things.+Then, in one terminal run the OCR API [(just a temporary hack until something cleaner)](https://github.com/louis030195/screen-pipe/issues/7):-## Installation+```bash+virtualenv env+source env/bin/activate+pip install fastapi uvicorn pytesseract pillow+uvicorn main:app --reload+```-To install ScreenPipe, run the following command in your terminal:+And (you need Rust + Cargo installed) the Rust CLI:```bash-git clone https://github.com/louis030195/screen-pipecargo install --path screenpipe-# test-screenpipe --path ./second-memory+screenpipe```+Check the `target/screenshots` directory now :)+++https://github.com/louis030195/screen-pipe/assets/25003283/08a8c9d6-0be6-44c2-b37f-62d0721fe8c3++## Why open source?Recent breakthroughs in AI have shown that context is the final frontier. AI will soon be able to incorporate the context of an entire human life into its 'prompt', and the technologies that enable this kind of personalisation should be available to all developers to accelerate access to the next stage of our evolution.diff --git a/main.py b/main.pynew file mode 100644index 000000000..21ddab78c--- /dev/null+++ b/main.py@@ -0,0 +1,29 @@+# just a quick & dirty local OCR api until something cleaner is done https://github.com/louis030195/screen-pipe/issues/7+# virtualenv env+# source env/bin/activate+# pip install fastapi uvicorn pytesseract pillow+# uvicorn main:app --reload++from fastapi import FastAPI, File, UploadFile+from fastapi.responses import JSONResponse+from PIL import Image+import pytesseract+import io++app = FastAPI()+[email protected]("/ocr/")+async def perform_ocr(file: UploadFile = File(...)):+ try:+ # Read the uploaded file+ image = Image.open(io.BytesIO(await file.read()))++ # Perform OCR using pytesseract+ text = pytesseract.image_to_string(image)++ return JSONResponse(content={"text": text})+ except Exception as e:+ return JSONResponse(content={"error": str(e)}, status_code=500)++# To run the server, use the command: uvicorn main:app --reload+diff --git a/screenpipe/Cargo.toml b/screenpipe/Cargo.tomlindex 1657050b0..c81160b7e 100644--- a/screenpipe/Cargo.toml+++ b/screenpipe/Cargo.toml@@ -9,7 +9,10 @@ clap = { version = "4.0", features = ["derive"] }chrono = "0.4.38"crossbeam = "0.8"ctrlc = "3.4"+reqwest = { version = "0.11", features = ["json", "multipart"] }tokio = { version = "1.38", features = ["full"] }+serde = "1.0"+serde_json = "1.0"[[bin]]name = "screenpipe"diff --git a/screenpipe/src/main.rs b/screenpipe/src/main.rsindex a3812983c..189dce079 100644--- a/screenpipe/src/main.rs+++ b/screenpipe/src/main.rs@@ -1,7 +1,10 @@use chrono::Local;use clap::Parser;use crossbeam::channel;-use std::fs::create_dir_all;+use reqwest::Client;+use std::fs::{create_dir_all, File};+use std::io::Read;+use std::io::Write;use std::sync::atomic::{AtomicBool, Ordering};use std::sync::Arc;use std::thread::{self, sleep};@@ -46,12 +49,40 @@ fn normalized(filename: &str) -> String {.replace("/", "")}+async fn call_ocr_api(image_path: &str) -> Result<String, reqwest::Error> {+ let client = Client::new();+ let mut file = File::open(image_path).expect("Failed to open image file");+ let mut buffer = Vec::new();+ file.read_to_end(&mut buffer)+ .expect("Failed to read image file");++ let part = reqwest::multipart::Part::bytes(buffer).file_name(image_path.to_string());+ let form = reqwest::multipart::Form::new().part("file", part);++ let response = client+ .post("http://127.0.0.1:8000/ocr/")+ .multipart(form)+ .send()+ .await?;++ let text = response.text().await?;+ Ok(text)+}+async fn process_image(filename: String) {// Example async post-processing function// Perform tasks like extracting text or making API calls hereprintln!("Processing image asynchronously: {}", filename);// Simulate async work- tokio::time::sleep(Duration::from_secs(1)).await;+ // tokio::time::sleep(Duration::from_secs(1)).await;+ let text = call_ocr_api(&filename).await.unwrap();+ println!("OCR result: {}", text);++ // Create a JSON object+ let json = serde_json::json!({ "text": text });+ let new_filename = filename.replace(".png", ".json");+ let mut file = File::create(new_filename).unwrap();+ file.write_all(json.to_string().as_bytes()).unwrap();}fn screenpipe(path: &str, interval: f32, running: Arc<AtomicBool>) {