ChaterJee 0.2.6__tar.gz → 0.2.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -148,7 +148,7 @@ class ChatLogs:
148
148
 
149
149
  return ConversationHandler.END
150
150
 
151
- def get_last_line(self, filepath):
151
+ def get_last_line0(self, filepath):
152
152
  with open(filepath, 'rb') as f:
153
153
  # Go to the end of file
154
154
  f.seek(0, 2)
@@ -168,6 +168,40 @@ class ChatLogs:
168
168
  last_line = f.read().decode('utf-8')
169
169
  return last_line.strip()
170
170
 
171
+ def get_last_line(filepath):
172
+ with open(filepath, 'rb') as f:
173
+ # Go to the end of file
174
+ f.seek(0, 2)
175
+ end = f.tell()
176
+ pos = end - 1
177
+ last_non_empty_pos = None
178
+
179
+ # Step backwards to find last non-empty line
180
+ while pos >= 0:
181
+ f.seek(pos)
182
+ char = f.read(1)
183
+
184
+ # If we find a newline, check if we've collected non-whitespace since last newline
185
+ if char == b'\n':
186
+ if last_non_empty_pos is not None:
187
+ break
188
+ # Skip empty lines at the end
189
+ end = pos
190
+ elif not char.isspace():
191
+ # Track position of last non-whitespace character
192
+ last_non_empty_pos = pos
193
+
194
+ pos -= 1
195
+
196
+ # If file is empty or only contains whitespace
197
+ if last_non_empty_pos is None:
198
+ return None
199
+
200
+ # Read the last non-empty line
201
+ f.seek(last_non_empty_pos + 1 if last_non_empty_pos != end else 0)
202
+ last_line = f.read(end - f.tell()).decode('utf-8')
203
+ return last_line.strip()
204
+
171
205
  async def cancel(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
172
206
  self.smsID.append(update.message.message_id)
173
207
  await context.bot.sendChatAction(chat_id=self.CHATID, action="typing")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ChaterJee
3
- Version: 0.2.6
3
+ Version: 0.2.8
4
4
  Summary: Communicate your project updates via Telegram Bot!
5
5
  Author: Pallab Dutta
6
6
  Author-email: pallab9997@gmail.com
@@ -19,7 +19,13 @@ These are probably the most boring, time-consuming, yet unavoidable phases in ou
19
19
  Let me introduce ChaterJee to you — a playful fusion of `Chater`, meaning one who chats, and `Jee`, an honorific used in Indian culture to show respect. Think of `ChaterJee` as the lab assistant you always wanted — one who actually responds, never crashes your code, doesn't ask for co-authorship, and definitely doesn't need coffee all the time, unlike you.
20
20
 
21
21
  # Installation
22
- You need two things:
22
+ As a prerequisite you are required to install the `jq` library for reading JSON files from bash script.
23
+ ```bash
24
+ sudo apt update
25
+ sudo apt install jq
26
+ ```
27
+
28
+ Now, you need two things:
23
29
  1. The `ChaterJee` module
24
30
  2. A telegram BOT that you own
25
31
 
@@ -60,27 +66,79 @@ https://api.telegram.org/bot123456789:ABCdefGhiJKlmNoPQRsTuvWXyz/getUpdates
60
66
  - `ChatLogs` class: This reads log files, the last line is sent to you via the BOT. It can also share you final plots that you need for your next rerun.
61
67
 
62
68
  ## The minimal example
63
- This will register your JOB with the given `JOB_NAME` and logfiles into a JSON file, `<your home>/.data/JOB_status.json`.
69
+ This will register your JOB with the given `JOBNAME` and logfiles into a JSON file, `<your home>/.data/JOB_status.json`.
64
70
 
71
+ `script.py`
65
72
  ```python
66
73
  # This is a minimal example
74
+
75
+ # Your imports
76
+ from pathlib import Path
67
77
  import ChaterJee
78
+ import json
68
79
 
69
80
  # your code here
70
- JOB_NAME = "job_0.1.10"
71
- OUT_NAME = "experiment_0.1"
72
-
73
- for i in range(N):
74
- # Your code here
75
- notelogs = ChaterJee.NoteLogs()
76
- notelogs.write(f"{JOB_NAME}",\
77
- logSTRING=f"Step {i} done.",\
78
- logFILE=f"{OUT_NAME}.log",\
79
- logIMAGE=f"{OUT_NAME}.png")
80
- ```
81
+ with open("hyperparams.json","r") as ffr:
82
+ HYPERPARAMS = json.load(ffr)
83
+ # get your parameters
84
+ JOBNAME = HYPERPARAMS["JOBNAME"]
85
+ LOGDIR = HYPERPARAMS["LOGDIR"]
86
+ LOGFILE = HYPERPARAMS["LOGFILE"]
87
+ LOGIMAGE = HYPERPARAMS["LOGIMAGE"]
88
+
89
+ notelogs = ChaterJee.NoteLogs()
90
+ notelogs.write(
91
+ jobNAME=JOBNAME,
92
+ logDIR=LOGDIR,
93
+ logFILE=LOGFILE,
94
+ logIMAGE=LOGIMAGE
95
+ )
96
+
97
+ ### Your code that generates logs
98
+ print(f"{logs}")
99
+
100
+ ### Your code that generates plot
101
+ logPath = Path(LOGDIR)
102
+ plt.savefig(logPath / LOGIMAGE)
103
+ ```
104
+
105
+ The `hyperparams.json` file should look like the following. It must contain the last 4 `{key: value}` pairs to let our BOT access the log results.
106
+
107
+ `hyperparams.json`
108
+ ```json
109
+ {
110
+ .
111
+ .
112
+
113
+ "JOBNAME": "model_2.4",
114
+ "LOGDIR": "./run_2.4",
115
+ "LOGFILE": "outFile.log",
116
+ "LOGIMAGE": "outImage.png"
117
+ }
118
+ ```
119
+ Save the following script in your working directory to rerun your tuning experiments quickly.
120
+
121
+ `run.sh`
122
+ ```bash
123
+ #!/bin/bash
124
+
125
+ # Path to hyperparameter file
126
+ hyparam_file="hyperparams.json"
127
+
128
+ # Read values from config.json using jq
129
+ stdout_log=$(jq -r '.LOGFILE' "$hyparam_file")
130
+ stdout_dir=$(jq -r '.LOGDIR' "$hyparam_file")
131
+
132
+ # Create log directory
133
+ mkdir -p "$stdout_dir"
134
+
135
+ # Run the Python script with redirected logs
136
+ nohup python script.py --hyprm "$hyparam_file" > "$stdout_dir/$stdout_log" 2> "$stdout_dir/error.log" &
137
+ ```
81
138
 
82
139
  Next step is to receive updates on your projects.
83
140
 
141
+ `updater.py`
84
142
  ```python
85
143
  # Run this instance separately to parse job updates
86
144
  # This is the one which actually communicates with your BOT.
@@ -94,3 +152,15 @@ if __name__ == '__main__':
94
152
  cbot = ChaterJee.ChatLogs(TOKEN, CHATID)
95
153
  cbot.cmdTRIGGER()
96
154
  ```
155
+ Run the above script in a separate terminal session to start interacting with your BOT.
156
+
157
+ ## At your Telegram App
158
+ - Think your inbox as the terminal.
159
+ - `cd`, `ls` etc. works as expected. Therefore to go to parent directory, you simply type: `cd ..` , and to list contents type `ls` . You can run the `run.sh` executable just by typing `./run.sh` .
160
+ - texts starting with `/` are telegram-BOT commands.
161
+
162
+ At this stage the following 4 commands work:
163
+ - `/start` : Starts the conversation with the BOT.
164
+ - `/jobs` : List the jobs as Keyboard button options.
165
+ - `/clear` : Clears the chat history once you allow.
166
+ - `/edit file.json` : Let you edit and save the JSON file by the webapp Editor Babu.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ChaterJee
3
- Version: 0.2.6
3
+ Version: 0.2.8
4
4
  Summary: Communicate your project updates via Telegram Bot!
5
5
  Author: Pallab Dutta
6
6
  Author-email: pallab9997@gmail.com
@@ -19,7 +19,13 @@ These are probably the most boring, time-consuming, yet unavoidable phases in ou
19
19
  Let me introduce ChaterJee to you — a playful fusion of `Chater`, meaning one who chats, and `Jee`, an honorific used in Indian culture to show respect. Think of `ChaterJee` as the lab assistant you always wanted — one who actually responds, never crashes your code, doesn't ask for co-authorship, and definitely doesn't need coffee all the time, unlike you.
20
20
 
21
21
  # Installation
22
- You need two things:
22
+ As a prerequisite you are required to install the `jq` library for reading JSON files from bash script.
23
+ ```bash
24
+ sudo apt update
25
+ sudo apt install jq
26
+ ```
27
+
28
+ Now, you need two things:
23
29
  1. The `ChaterJee` module
24
30
  2. A telegram BOT that you own
25
31
 
@@ -60,27 +66,79 @@ https://api.telegram.org/bot123456789:ABCdefGhiJKlmNoPQRsTuvWXyz/getUpdates
60
66
  - `ChatLogs` class: This reads log files, the last line is sent to you via the BOT. It can also share you final plots that you need for your next rerun.
61
67
 
62
68
  ## The minimal example
63
- This will register your JOB with the given `JOB_NAME` and logfiles into a JSON file, `<your home>/.data/JOB_status.json`.
69
+ This will register your JOB with the given `JOBNAME` and logfiles into a JSON file, `<your home>/.data/JOB_status.json`.
64
70
 
71
+ `script.py`
65
72
  ```python
66
73
  # This is a minimal example
74
+
75
+ # Your imports
76
+ from pathlib import Path
67
77
  import ChaterJee
78
+ import json
68
79
 
69
80
  # your code here
70
- JOB_NAME = "job_0.1.10"
71
- OUT_NAME = "experiment_0.1"
72
-
73
- for i in range(N):
74
- # Your code here
75
- notelogs = ChaterJee.NoteLogs()
76
- notelogs.write(f"{JOB_NAME}",\
77
- logSTRING=f"Step {i} done.",\
78
- logFILE=f"{OUT_NAME}.log",\
79
- logIMAGE=f"{OUT_NAME}.png")
80
- ```
81
+ with open("hyperparams.json","r") as ffr:
82
+ HYPERPARAMS = json.load(ffr)
83
+ # get your parameters
84
+ JOBNAME = HYPERPARAMS["JOBNAME"]
85
+ LOGDIR = HYPERPARAMS["LOGDIR"]
86
+ LOGFILE = HYPERPARAMS["LOGFILE"]
87
+ LOGIMAGE = HYPERPARAMS["LOGIMAGE"]
88
+
89
+ notelogs = ChaterJee.NoteLogs()
90
+ notelogs.write(
91
+ jobNAME=JOBNAME,
92
+ logDIR=LOGDIR,
93
+ logFILE=LOGFILE,
94
+ logIMAGE=LOGIMAGE
95
+ )
96
+
97
+ ### Your code that generates logs
98
+ print(f"{logs}")
99
+
100
+ ### Your code that generates plot
101
+ logPath = Path(LOGDIR)
102
+ plt.savefig(logPath / LOGIMAGE)
103
+ ```
104
+
105
+ The `hyperparams.json` file should look like the following. It must contain the last 4 `{key: value}` pairs to let our BOT access the log results.
106
+
107
+ `hyperparams.json`
108
+ ```json
109
+ {
110
+ .
111
+ .
112
+
113
+ "JOBNAME": "model_2.4",
114
+ "LOGDIR": "./run_2.4",
115
+ "LOGFILE": "outFile.log",
116
+ "LOGIMAGE": "outImage.png"
117
+ }
118
+ ```
119
+ Save the following script in your working directory to rerun your tuning experiments quickly.
120
+
121
+ `run.sh`
122
+ ```bash
123
+ #!/bin/bash
124
+
125
+ # Path to hyperparameter file
126
+ hyparam_file="hyperparams.json"
127
+
128
+ # Read values from config.json using jq
129
+ stdout_log=$(jq -r '.LOGFILE' "$hyparam_file")
130
+ stdout_dir=$(jq -r '.LOGDIR' "$hyparam_file")
131
+
132
+ # Create log directory
133
+ mkdir -p "$stdout_dir"
134
+
135
+ # Run the Python script with redirected logs
136
+ nohup python script.py --hyprm "$hyparam_file" > "$stdout_dir/$stdout_log" 2> "$stdout_dir/error.log" &
137
+ ```
81
138
 
82
139
  Next step is to receive updates on your projects.
83
140
 
141
+ `updater.py`
84
142
  ```python
85
143
  # Run this instance separately to parse job updates
86
144
  # This is the one which actually communicates with your BOT.
@@ -94,3 +152,15 @@ if __name__ == '__main__':
94
152
  cbot = ChaterJee.ChatLogs(TOKEN, CHATID)
95
153
  cbot.cmdTRIGGER()
96
154
  ```
155
+ Run the above script in a separate terminal session to start interacting with your BOT.
156
+
157
+ ## At your Telegram App
158
+ - Think your inbox as the terminal.
159
+ - `cd`, `ls` etc. works as expected. Therefore to go to parent directory, you simply type: `cd ..` , and to list contents type `ls` . You can run the `run.sh` executable just by typing `./run.sh` .
160
+ - texts starting with `/` are telegram-BOT commands.
161
+
162
+ At this stage the following 4 commands work:
163
+ - `/start` : Starts the conversation with the BOT.
164
+ - `/jobs` : List the jobs as Keyboard button options.
165
+ - `/clear` : Clears the chat history once you allow.
166
+ - `/edit file.json` : Let you edit and save the JSON file by the webapp Editor Babu.
@@ -9,7 +9,13 @@ These are probably the most boring, time-consuming, yet unavoidable phases in ou
9
9
  Let me introduce ChaterJee to you — a playful fusion of `Chater`, meaning one who chats, and `Jee`, an honorific used in Indian culture to show respect. Think of `ChaterJee` as the lab assistant you always wanted — one who actually responds, never crashes your code, doesn't ask for co-authorship, and definitely doesn't need coffee all the time, unlike you.
10
10
 
11
11
  # Installation
12
- You need two things:
12
+ As a prerequisite you are required to install the `jq` library for reading JSON files from bash script.
13
+ ```bash
14
+ sudo apt update
15
+ sudo apt install jq
16
+ ```
17
+
18
+ Now, you need two things:
13
19
  1. The `ChaterJee` module
14
20
  2. A telegram BOT that you own
15
21
 
@@ -50,27 +56,79 @@ https://api.telegram.org/bot123456789:ABCdefGhiJKlmNoPQRsTuvWXyz/getUpdates
50
56
  - `ChatLogs` class: This reads log files, the last line is sent to you via the BOT. It can also share you final plots that you need for your next rerun.
51
57
 
52
58
  ## The minimal example
53
- This will register your JOB with the given `JOB_NAME` and logfiles into a JSON file, `<your home>/.data/JOB_status.json`.
59
+ This will register your JOB with the given `JOBNAME` and logfiles into a JSON file, `<your home>/.data/JOB_status.json`.
54
60
 
61
+ `script.py`
55
62
  ```python
56
63
  # This is a minimal example
64
+
65
+ # Your imports
66
+ from pathlib import Path
57
67
  import ChaterJee
68
+ import json
58
69
 
59
70
  # your code here
60
- JOB_NAME = "job_0.1.10"
61
- OUT_NAME = "experiment_0.1"
62
-
63
- for i in range(N):
64
- # Your code here
65
- notelogs = ChaterJee.NoteLogs()
66
- notelogs.write(f"{JOB_NAME}",\
67
- logSTRING=f"Step {i} done.",\
68
- logFILE=f"{OUT_NAME}.log",\
69
- logIMAGE=f"{OUT_NAME}.png")
70
- ```
71
+ with open("hyperparams.json","r") as ffr:
72
+ HYPERPARAMS = json.load(ffr)
73
+ # get your parameters
74
+ JOBNAME = HYPERPARAMS["JOBNAME"]
75
+ LOGDIR = HYPERPARAMS["LOGDIR"]
76
+ LOGFILE = HYPERPARAMS["LOGFILE"]
77
+ LOGIMAGE = HYPERPARAMS["LOGIMAGE"]
78
+
79
+ notelogs = ChaterJee.NoteLogs()
80
+ notelogs.write(
81
+ jobNAME=JOBNAME,
82
+ logDIR=LOGDIR,
83
+ logFILE=LOGFILE,
84
+ logIMAGE=LOGIMAGE
85
+ )
86
+
87
+ ### Your code that generates logs
88
+ print(f"{logs}")
89
+
90
+ ### Your code that generates plot
91
+ logPath = Path(LOGDIR)
92
+ plt.savefig(logPath / LOGIMAGE)
93
+ ```
94
+
95
+ The `hyperparams.json` file should look like the following. It must contain the last 4 `{key: value}` pairs to let our BOT access the log results.
96
+
97
+ `hyperparams.json`
98
+ ```json
99
+ {
100
+ .
101
+ .
102
+
103
+ "JOBNAME": "model_2.4",
104
+ "LOGDIR": "./run_2.4",
105
+ "LOGFILE": "outFile.log",
106
+ "LOGIMAGE": "outImage.png"
107
+ }
108
+ ```
109
+ Save the following script in your working directory to rerun your tuning experiments quickly.
110
+
111
+ `run.sh`
112
+ ```bash
113
+ #!/bin/bash
114
+
115
+ # Path to hyperparameter file
116
+ hyparam_file="hyperparams.json"
117
+
118
+ # Read values from config.json using jq
119
+ stdout_log=$(jq -r '.LOGFILE' "$hyparam_file")
120
+ stdout_dir=$(jq -r '.LOGDIR' "$hyparam_file")
121
+
122
+ # Create log directory
123
+ mkdir -p "$stdout_dir"
124
+
125
+ # Run the Python script with redirected logs
126
+ nohup python script.py --hyprm "$hyparam_file" > "$stdout_dir/$stdout_log" 2> "$stdout_dir/error.log" &
127
+ ```
71
128
 
72
129
  Next step is to receive updates on your projects.
73
130
 
131
+ `updater.py`
74
132
  ```python
75
133
  # Run this instance separately to parse job updates
76
134
  # This is the one which actually communicates with your BOT.
@@ -84,3 +142,15 @@ if __name__ == '__main__':
84
142
  cbot = ChaterJee.ChatLogs(TOKEN, CHATID)
85
143
  cbot.cmdTRIGGER()
86
144
  ```
145
+ Run the above script in a separate terminal session to start interacting with your BOT.
146
+
147
+ ## At your Telegram App
148
+ - Think your inbox as the terminal.
149
+ - `cd`, `ls` etc. works as expected. Therefore to go to parent directory, you simply type: `cd ..` , and to list contents type `ls` . You can run the `run.sh` executable just by typing `./run.sh` .
150
+ - texts starting with `/` are telegram-BOT commands.
151
+
152
+ At this stage the following 4 commands work:
153
+ - `/start` : Starts the conversation with the BOT.
154
+ - `/jobs` : List the jobs as Keyboard button options.
155
+ - `/clear` : Clears the chat history once you allow.
156
+ - `/edit file.json` : Let you edit and save the JSON file by the webapp Editor Babu.
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='ChaterJee',
5
- version='0.2.6',
5
+ version='0.2.8',
6
6
  packages=find_packages(),
7
7
  install_requires=[
8
8
  'python-telegram-bot==20.7',
File without changes