cspocketindia commited on
Commit
3cb4215
1 Parent(s): 282953b

added scheduler

Browse files
Files changed (2) hide show
  1. gradio_app.py +16 -13
  2. requirements.txt +2 -1
gradio_app.py CHANGED
@@ -3,6 +3,7 @@ import time
3
  import csv
4
  import datetime
5
  import gradio
 
6
  from gradio import utils
7
  import huggingface_hub
8
  from pathlib import Path
@@ -27,8 +28,7 @@ repo = huggingface_hub.Repository(
27
  )
28
  repo.git_pull(lfs=True)
29
 
30
- def log_record(vals):
31
-
32
  log_file = Path(dataset_dir) / "data.csv"
33
  is_new = not Path(log_file).exists()
34
  with open(log_file, "a", newline="", encoding="utf-8") as csvfile:
@@ -37,13 +37,8 @@ def log_record(vals):
37
  writer.writerow(utils.sanitize_list_for_csv(headers))
38
  writer.writerow(utils.sanitize_list_for_csv(vals))
39
 
40
- with open(log_file, "r", encoding="utf-8") as csvfile:
41
- line_count = len([None for _ in csv.reader(csvfile)]) - 1
42
- repo.git_add()
43
- repo.git_commit(f"Logged sample #{line_count}")
44
- repo.git_push()
45
- # repo.push_to_hub(commit_message=f"Logged sample #{line_count}")
46
-
47
 
48
  def predict(sentence):
49
 
@@ -54,7 +49,7 @@ def predict(sentence):
54
 
55
  output = classes[predictions[0]]
56
 
57
- print(f"Sentence: {sentence} \nPredictions: {predictions} - {output}")
58
  log_record([sentence, output, timestamp, str(elapsed_time)])
59
 
60
  return output
@@ -64,7 +59,15 @@ gradio.Interface(
64
  fn=predict,
65
  inputs="text",
66
  outputs="text",
67
- allow_flagging='auto',
68
- flagging_dir='logs',
69
- flagging_callback=gradio.SimpleCSVLogger(),
70
  ).launch()
 
 
 
 
 
 
 
 
 
 
 
3
  import csv
4
  import datetime
5
  import gradio
6
+ import schedule
7
  from gradio import utils
8
  import huggingface_hub
9
  from pathlib import Path
 
28
  )
29
  repo.git_pull(lfs=True)
30
 
31
+ def log_record(vals):
 
32
  log_file = Path(dataset_dir) / "data.csv"
33
  is_new = not Path(log_file).exists()
34
  with open(log_file, "a", newline="", encoding="utf-8") as csvfile:
 
37
  writer.writerow(utils.sanitize_list_for_csv(headers))
38
  writer.writerow(utils.sanitize_list_for_csv(vals))
39
 
40
+ # with open(log_file, "r", encoding="utf-8") as csvfile:
41
+ # line_count = len([None for _ in csv.reader(csvfile)]) - 1
 
 
 
 
 
42
 
43
  def predict(sentence):
44
 
 
49
 
50
  output = classes[predictions[0]]
51
 
52
+ print(f"Sentence: {sentence} \nPrediction: {predictions[0]} - {output}")
53
  log_record([sentence, output, timestamp, str(elapsed_time)])
54
 
55
  return output
 
59
  fn=predict,
60
  inputs="text",
61
  outputs="text",
62
+ allow_flagging='never'
 
 
63
  ).launch()
64
+
65
+
66
+ def sync_logs():
67
+ if not repo.is_repo_clean():
68
+ repo.git_add()
69
+ repo.git_commit()
70
+ # repo.git_push()
71
+ repo.push_to_hub()
72
+
73
+ schedule.every(2).minutes.do(sync_logs)
requirements.txt CHANGED
@@ -14,4 +14,5 @@ flask
14
  torch
15
  torchvision
16
  scikit-learn
17
- numpy
 
 
14
  torch
15
  torchvision
16
  scikit-learn
17
+ numpy
18
+ schedule