Update app.py
Browse files
app.py
CHANGED
@@ -25,16 +25,24 @@ def save_to_repo():
|
|
25 |
os.system('git commit -m "Update flagged data"')
|
26 |
os.system("git push origin main") # Push updated file to the repo
|
27 |
|
|
|
28 |
|
29 |
'''
|
30 |
in order to keep track of what the last prompt was that was given human feedback
|
31 |
'''
|
32 |
def load_state():
|
|
|
|
|
|
|
33 |
try:
|
34 |
-
with open(
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# Save state to file
|
40 |
def save_state(count):
|
|
|
25 |
os.system('git commit -m "Update flagged data"')
|
26 |
os.system("git push origin main") # Push updated file to the repo
|
27 |
|
28 |
+
STATE_FILE = "state.json"
|
29 |
|
30 |
'''
|
31 |
in order to keep track of what the last prompt was that was given human feedback
|
32 |
'''
|
33 |
def load_state():
|
34 |
+
if not os.path.exists(STATE_FILE): # Handle missing file
|
35 |
+
return 0 # Default count value
|
36 |
+
|
37 |
try:
|
38 |
+
with open(STATE_FILE, "r") as f:
|
39 |
+
content = f.read().strip() # Remove leading/trailing spaces
|
40 |
+
if not content: # Handle empty file
|
41 |
+
return 0 # Default count value
|
42 |
+
return json.loads(content).get("count", 0) # Safely parse JSON
|
43 |
+
except (json.JSONDecodeError, OSError): # Catch JSON errors or I/O issues
|
44 |
+
return 0 # Default count value
|
45 |
+
#if the file doesn't have count variable in it, then it will return 0, which is good - that's the first index
|
46 |
|
47 |
# Save state to file
|
48 |
def save_state(count):
|