-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-summaries.sh
72 lines (57 loc) · 2.38 KB
/
get-summaries.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# Define global summary file and supersummary file
global_summary_file="overview.txt"
supersummary_file="supersummary.txt"
# Create or clear the global summary file and supersummary file
echo "Global Processing Summary" > "$global_summary_file"
echo "========================" >> "$global_summary_file"
echo "Supersummary of Overviews" > "$supersummary_file"
echo "========================" >> "$supersummary_file"
# Function to check if a file is already processed
is_processed() {
grep -Fxq "$1" "$main_dir/$progress_file"
}
# Function to process files in a specific directory, excluding overview.txt initially
process_files_in_dir() {
local dir=$1
local progress_file="$dir/progress.log"
local overview_file="$dir/overview.txt"
# Create progress file if it doesn't exist
touch "$progress_file"
# Initialize or clear the overview file
echo "Processing Overview for $dir" > "$overview_file"
echo "============================" >> "$overview_file"
# Iterate over each .txt file in the specified directory except overview.txt
for file in "$dir"/*.txt; do
if [ "$file" != "$overview_file" ]; then
if [ -f "$file" ]; then
local file_path=$(pwd)/"$file"
if ! is_processed "$file_path"; then
echo "Checking $file"
echo "Checking $file" >> "$overview_file"
# Replace `ollama run wizardlm2` with your actual processing command
ollama run wizardlm2 "Summarize:" < "$file" | tee -a "$overview_file"
echo "$file_path" >> "$progress_file"
fi
fi
fi
done
# Summarize the overview file itself and append to supersummary
echo "Summary for $dir:" >> "$supersummary_file"
ollama run wizardlm2 "Summarize:" < "$overview_file" | tee -a "$supersummary_file"
echo "========================" >> "$supersummary_file"
}
# Get the current directory
main_dir=$(pwd)
# Iterate over each subdirectory in the current directory
for dir in */; do
# Remove trailing slash from directory name
dir=${dir%/}
# Check if it's a directory
if [ -d "$dir" ]; then
echo "Processing directory: $dir"
# Process files in the current subdirectory
process_files_in_dir "$dir"
fi
done
echo "Processing complete. Check $supersummary_file for global summary."