TEZv commited on
Commit
4301072
·
verified ·
1 Parent(s): 63777cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -17
app.py CHANGED
@@ -16,26 +16,32 @@ ACC = "#f97316"
16
  ACC2 = "#38bdf8"
17
  TXT = "#f1f5f9"
18
 
19
- LOG_PATH = Path("./lab_journal.csv")
20
 
21
  def log_entry(tab, inputs, result, note=""):
22
- write_header = not LOG_PATH.exists()
23
- with open(LOG_PATH, "a", newline="", encoding="utf-8") as f:
24
- w = csv.DictWriter(f, fieldnames=["timestamp","tab","inputs","result","note"])
25
- if write_header:
26
- w.writeheader()
27
- w.writerow({
28
- "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M"),
29
- "tab": tab,
30
- "inputs": str(inputs),
31
- "result": str(result)[:200],
32
- "note": note
33
- })
 
 
 
34
 
35
  def load_journal():
36
- if not LOG_PATH.exists():
 
 
 
 
37
  return pd.DataFrame(columns=["timestamp","tab","inputs","result","note"])
38
- return pd.read_csv(LOG_PATH)
39
 
40
  def save_note(note, tab, last_result):
41
  log_entry(tab, "", last_result, note)
@@ -600,5 +606,4 @@ with gr.Blocks(css=css, title="K R&D Lab") as demo:
600
  "[KOSATIKS GROUP 🦈](https://kosatiks-group.pp.ua)"
601
  )
602
 
603
- if __name__ == "__main__":
604
- demo.launch()
 
16
  ACC2 = "#38bdf8"
17
  TXT = "#f1f5f9"
18
 
19
+ LOG_PATH = Path("/tmp/lab_journal.csv")
20
 
21
  def log_entry(tab, inputs, result, note=""):
22
+ try:
23
+ write_header = not LOG_PATH.exists()
24
+ with open(LOG_PATH, "a", newline="", encoding="utf-8") as f:
25
+ w = csv.DictWriter(f, fieldnames=["timestamp","tab","inputs","result","note"])
26
+ if write_header:
27
+ w.writeheader()
28
+ w.writerow({
29
+ "timestamp": datetime.now().strftime("%Y-%m-%d %H:%M"),
30
+ "tab": tab,
31
+ "inputs": str(inputs),
32
+ "result": str(result)[:200],
33
+ "note": note
34
+ })
35
+ except Exception:
36
+ pass
37
 
38
  def load_journal():
39
+ try:
40
+ if not LOG_PATH.exists():
41
+ return pd.DataFrame(columns=["timestamp","tab","inputs","result","note"])
42
+ return pd.read_csv(LOG_PATH)
43
+ except Exception:
44
  return pd.DataFrame(columns=["timestamp","tab","inputs","result","note"])
 
45
 
46
  def save_note(note, tab, last_result):
47
  log_entry(tab, "", last_result, note)
 
606
  "[KOSATIKS GROUP 🦈](https://kosatiks-group.pp.ua)"
607
  )
608
 
609
+ demo.launch(server_name="0.0.0.0", server_port=7860)