Spaces:
Runtime error
Runtime error
cspocketindia
commited on
Commit
·
a5cbba4
1
Parent(s):
5ee5c89
added timestamp to logs
Browse files- gradio_app.py +12 -4
gradio_app.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
import os
|
|
|
2 |
import csv
|
|
|
3 |
import gradio
|
4 |
from gradio import utils
|
5 |
import huggingface_hub
|
@@ -15,7 +17,7 @@ hf_token = os.getenv("HF_TOKEN")
|
|
15 |
|
16 |
dataset_dir = "logs"
|
17 |
|
18 |
-
headers = ["input", "output"]
|
19 |
|
20 |
|
21 |
repo = huggingface_hub.Repository(
|
@@ -24,7 +26,7 @@ repo = huggingface_hub.Repository(
|
|
24 |
token=hf_token,
|
25 |
)
|
26 |
|
27 |
-
def log_record(
|
28 |
repo.git_pull(lfs=True)
|
29 |
|
30 |
log_file = Path(dataset_dir) / "data.csv"
|
@@ -37,7 +39,7 @@ def log_record(input, output):
|
|
37 |
if is_new:
|
38 |
writer.writerow(utils.sanitize_list_for_csv(headers))
|
39 |
|
40 |
-
writer.writerow(utils.sanitize_list_for_csv(
|
41 |
|
42 |
with open(log_file, "r", encoding="utf-8") as csvfile:
|
43 |
line_count = len([None for _ in csv.reader(csvfile)]) - 1
|
@@ -49,13 +51,19 @@ def predict(sentence):
|
|
49 |
|
50 |
print(sentence)
|
51 |
|
|
|
|
|
|
|
|
|
52 |
predictions = model.evaluate([sentence])
|
53 |
|
|
|
|
|
54 |
print(f"Predictions: {predictions}")
|
55 |
|
56 |
output = classes[predictions[0]]
|
57 |
|
58 |
-
log_record(sentence, output)
|
59 |
|
60 |
return output
|
61 |
|
|
|
1 |
import os
|
2 |
+
import time
|
3 |
import csv
|
4 |
+
import datetime
|
5 |
import gradio
|
6 |
from gradio import utils
|
7 |
import huggingface_hub
|
|
|
17 |
|
18 |
dataset_dir = "logs"
|
19 |
|
20 |
+
headers = ["input", "output", "timestamp", "elapsed"]
|
21 |
|
22 |
|
23 |
repo = huggingface_hub.Repository(
|
|
|
26 |
token=hf_token,
|
27 |
)
|
28 |
|
29 |
+
def log_record(vals):
|
30 |
repo.git_pull(lfs=True)
|
31 |
|
32 |
log_file = Path(dataset_dir) / "data.csv"
|
|
|
39 |
if is_new:
|
40 |
writer.writerow(utils.sanitize_list_for_csv(headers))
|
41 |
|
42 |
+
writer.writerow(utils.sanitize_list_for_csv(vals))
|
43 |
|
44 |
with open(log_file, "r", encoding="utf-8") as csvfile:
|
45 |
line_count = len([None for _ in csv.reader(csvfile)]) - 1
|
|
|
51 |
|
52 |
print(sentence)
|
53 |
|
54 |
+
timestamp = datetime.datetime.now().isoformat()
|
55 |
+
|
56 |
+
start_time = time.time()
|
57 |
+
|
58 |
predictions = model.evaluate([sentence])
|
59 |
|
60 |
+
elapsed_time = time.time() - start_time
|
61 |
+
|
62 |
print(f"Predictions: {predictions}")
|
63 |
|
64 |
output = classes[predictions[0]]
|
65 |
|
66 |
+
log_record([sentence, output, timestamp, str(elapsed_time)])
|
67 |
|
68 |
return output
|
69 |
|