Skip to content

Commit

Permalink
chore: remove warning, restore cli release
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Jul 20, 2024
1 parent 3e9679b commit 0bf04d3
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 82 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# # Run for Linux
# act -W .github/workflows/release-app.yml --container-architecture linux/amd64 -j publish-tauri -P ubuntu-24.04

name: Release
name: Release App

on:
push:
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/release-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Release CLI

on:
push:
tags:
- "v*"
workflow_dispatch:

jobs:
build-ubuntu:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y libavformat-dev libavfilter-dev libavdevice-dev ffmpeg libasound2-dev
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

- name: Build with RPATH
run: |
export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig:$PKG_CONFIG_PATH"
export RUSTFLAGS="-C link-arg=-Wl,-rpath,\$ORIGIN/lib"
cargo build --release
- name: Copy FFmpeg libraries
run: |
mkdir -p target/release/lib
cp /usr/lib/x86_64-linux-gnu/libavcodec.so* target/release/lib/
cp /usr/lib/x86_64-linux-gnu/libavformat.so* target/release/lib/
cp /usr/lib/x86_64-linux-gnu/libavutil.so* target/release/lib/
cp /usr/lib/x86_64-linux-gnu/libswresample.so* target/release/lib/
cp /usr/lib/x86_64-linux-gnu/libswscale.so* target/release/lib/
cp /usr/lib/x86_64-linux-gnu/libavfilter.so* target/release/lib/
cp /usr/lib/x86_64-linux-gnu/libavdevice.so* target/release/lib/
- name: Create deployment package
run: |
mkdir -p screenpipe-linux
cp target/release/screenpipe screenpipe-linux/screenpipe
cp -r target/release/lib screenpipe-linux/
chmod +x screenpipe-linux/screenpipe
tar -czvf screenpipe-linux.tar.gz screenpipe-linux
- name: Upload Artifact
uses: actions/upload-artifact@v2
with:
name: screenpipe-linux
path: screenpipe-linux.tar.gz

release:
runs-on: ubuntu-latest
needs: [build-ubuntu]
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Download Artifacts
uses: actions/download-artifact@v2
with:
name: screenpipe-linux

- name: Set Version
shell: bash
run: |
echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
echo "RELEASE_VERSION=$(echo ${GITHUB_REF_NAME} | cut -f1 -d-)" >> $GITHUB_ENV
- name: Create or update Release
env:
GH_TOKEN: ${{ secrets.PAT }}
run: |
gh release create ${{ env.RELEASE_VERSION }} --title ${{ env.RELEASE_VERSION }} --generate-notes
gh release upload ${{ env.RELEASE_VERSION }} screenpipe-linux.tar.gz
71 changes: 46 additions & 25 deletions screenpipe-vision/src/core.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
use image::DynamicImage;
use log::{debug, error, info};
use log::{debug, error};
use rusty_tesseract::DataOutput;
use tokio::sync::{mpsc::{Receiver, Sender}, Mutex}; // Corrected import for Mutex
use serde_json;
use std::{collections::{HashMap, HashSet}, sync::Arc, time::{Duration, Instant}};
use xcap::Monitor;
use strsim::levenshtein;
use std::sync::atomic::{AtomicBool, Ordering};
use std::{
collections::{HashMap, HashSet},
sync::Arc,
time::{Duration, Instant},
};
use strsim::levenshtein;
use tokio::sync::{
mpsc::{Receiver, Sender},
Mutex,
}; // Corrected import for Mutex
use xcap::Monitor;

use crate::utils::{perform_ocr, save_text_files, capture_screenshot, compare_with_previous_image};
use crate::utils::{capture_screenshot, compare_with_previous_image, perform_ocr, save_text_files};

pub enum ControlMessage {
Pause,
Expand All @@ -32,16 +39,13 @@ pub struct OcrTaskData {
pub result_tx: Sender<CaptureResult>,
}

const MAX_THREADS: usize = 1;

pub async fn continuous_capture(
_control_rx: &mut Receiver<ControlMessage>,
result_tx: Sender<CaptureResult>,
interval: Duration,
save_text_files_flag: bool,
save_text_files_flag: bool,
) {
let monitor = Monitor::all().unwrap().first().unwrap().clone(); // Simplified monitor retrieval
let cache = Arc::new(Mutex::new(HashMap::<u64, String>::new()));
let previous_text_json = Arc::new(Mutex::new(None));
let ocr_task_running = Arc::new(AtomicBool::new(false));
let mut frame_counter: u64 = 0;
Expand All @@ -52,7 +56,14 @@ pub async fn continuous_capture(

loop {
let (image, image_hash, _capture_duration) = capture_screenshot(&monitor).await;
let current_average = compare_with_previous_image(&previous_image, &image, &mut max_average, frame_counter, &mut max_avg_value).await;
let current_average = compare_with_previous_image(
&previous_image,
&image,
&mut max_average,
frame_counter,
&mut max_avg_value,
)
.await;
if current_average > max_avg_value {
max_average = Some(MaxAverageFrame {
image: Arc::new(image.clone()),
Expand All @@ -70,15 +81,15 @@ pub async fn continuous_capture(

if !ocr_task_running.load(Ordering::SeqCst) {
// debug!("max_avg_frame {} before if let Some(", max_avg_value);
if let Some(max_avg_frame) = max_average.take() { // Use take() to move out the value
if let Some(max_avg_frame) = max_average.take() {
// Use take() to move out the value
let ocr_task_data = OcrTaskData {
image: max_avg_frame.image.clone(),
frame_number: max_avg_frame.frame_number,
timestamp: max_avg_frame.timestamp,
result_tx: result_tx.clone(),
};

let cache_clone = cache.clone();
let previous_text_json_clone = previous_text_json.clone();
let ocr_task_running_clone = ocr_task_running.clone();

Expand All @@ -90,10 +101,11 @@ pub async fn continuous_capture(
ocr_task_data.frame_number,
ocr_task_data.timestamp,
ocr_task_data.result_tx,
&cache_clone,
&previous_text_json_clone,
save_text_files_flag, // Pass the flag here
).await {
)
.await
{
error!("Error processing OCR task: {}", e);
}
ocr_task_running_clone.store(false, Ordering::SeqCst);
Expand All @@ -103,7 +115,6 @@ pub async fn continuous_capture(
// Reset max_average and max_avg_value after spawning the OCR task
max_avg_value = 0.0;
// debug!("max_avg_value {}", max_avg_value);

}
}

Expand Down Expand Up @@ -135,7 +146,6 @@ async fn process_ocr_task(
frame_number: u64,
timestamp: Instant,
result_tx: Sender<CaptureResult>,
cache: &Arc<Mutex<HashMap<u64, String>>>,
previous_text_json: &Arc<Mutex<Option<Vec<HashMap<String, String>>>>>,
save_text_files_flag: bool, // Add this parameter
) -> Result<(), std::io::Error> {
Expand All @@ -144,10 +154,11 @@ async fn process_ocr_task(
debug!("Performing OCR for frame {}", frame_number);
let (text, data_output, json_output) = perform_ocr(&image_arc);

let current_text_json: Vec<HashMap<String, String>> = serde_json::from_str(&json_output).unwrap_or_else(|e| {
error!("Failed to parse JSON output: {}", e);
Vec::new()
});
let current_text_json: Vec<HashMap<String, String>> = serde_json::from_str(&json_output)
.unwrap_or_else(|e| {
error!("Failed to parse JSON output: {}", e);
Vec::new()
});

let mut previous_text_json = previous_text_json.lock().await;
let mut new_text_json = Vec::new();
Expand All @@ -166,7 +177,8 @@ async fn process_ocr_task(
}
}
} else {
new_text_json = current_text_json.iter()
new_text_json = current_text_json
.iter()
.filter(|record| record["confidence"].parse::<f64>().unwrap_or(0.0) > 60.0)
.cloned()
.collect();
Expand All @@ -176,7 +188,13 @@ async fn process_ocr_task(
new_text_json.retain(|record| seen_texts.insert(record["text"].clone()));

if save_text_files_flag {
save_text_files(frame_number, &new_text_json, &current_text_json, &previous_text_json).await;
save_text_files(
frame_number,
&new_text_json,
&current_text_json,
&previous_text_json,
)
.await;
}

*previous_text_json = Some(current_text_json.clone());
Expand All @@ -193,12 +211,15 @@ async fn process_ocr_task(
.await
{
error!("Failed to send OCR result: {}", e);
return Err(std::io::Error::new(std::io::ErrorKind::Other, "Failed to send OCR result"));
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to send OCR result",
));
}
let _duration = start_time.elapsed();
debug!(
"OCR task processed frame {} in {:?}",
frame_number, _duration
);
Ok(())
}
}
Loading

0 comments on commit 0bf04d3

Please sign in to comment.