Spaces:
Sleeping
Sleeping
Kevin Louis
commited on
Commit
•
a7228f9
1
Parent(s):
dfbb079
Upload update added scheduled logging
Browse filesTest commit to update app file with scheduled commit functions
app.py
CHANGED
@@ -1,22 +1,35 @@
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
import pandas as pd
|
4 |
-
|
5 |
-
|
6 |
from parameter_extractor import ParameterExtractor
|
7 |
from DNAseq import DNAseq
|
8 |
-
from helper import list_at_index_0, list_at_index_1
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def chat_to_sequence(sequence, user_query):
|
12 |
|
13 |
-
# Log information to a CSV file
|
14 |
-
log_filename = "CTS_user_log.csv"
|
15 |
|
16 |
# Sequence to be analysed/queried
|
17 |
input_sequence = sequence
|
18 |
|
19 |
-
# Set
|
20 |
dna = input_sequence
|
21 |
|
22 |
# Model
|
@@ -113,23 +126,15 @@ def chat_to_sequence(sequence, user_query):
|
|
113 |
proximal_upper_threshold,
|
114 |
]
|
115 |
|
116 |
-
# Logger Testing Code
|
117 |
-
user_log = pd.read_csv(log_filename)
|
118 |
-
print(user_log.tail(3))
|
119 |
-
|
120 |
-
# Flagged folder test code
|
121 |
-
flagged_log = pd.read_csv("flagged/log.csv")
|
122 |
-
print(flagged_log.tail(2))
|
123 |
-
|
124 |
# Check the query score against threshold values
|
125 |
if query_score >= proximal_upper_threshold:
|
126 |
response = threshold_exceeded_message
|
127 |
-
|
128 |
print(threshold_exceeded_message)
|
129 |
|
130 |
elif proximal_lower_threshold < query_score < proximal_upper_threshold:
|
131 |
-
response = threshold_approximate_message + "
|
132 |
-
|
133 |
print(threshold_approximate_message, ref_question)
|
134 |
else:
|
135 |
print("Execute query")
|
@@ -144,11 +149,11 @@ def chat_to_sequence(sequence, user_query):
|
|
144 |
function = matching_row.iloc[0]["function"]
|
145 |
response = str(eval(function))
|
146 |
code_descript_message = query_code_description.title()
|
147 |
-
|
148 |
else:
|
149 |
response = "Error processing query"
|
150 |
query_code = "No Match Error"
|
151 |
-
|
152 |
print("No matching code found for the function:", code)
|
153 |
|
154 |
return response, code_descript_message
|
@@ -160,7 +165,7 @@ ChatToSequence = gr.Interface(
|
|
160 |
inputs=[gr.Textbox(label="Sequence", placeholder="Input DNA Sequence..."),
|
161 |
gr.Textbox(label="Query", placeholder="Input Query...")],
|
162 |
outputs=[gr.Textbox(label="Response"), gr.Textbox(label="Action Executed")],
|
163 |
-
allow_flagging="
|
164 |
title="Chat-To-Sequence",
|
165 |
description="This Demo App Allows You To Explore Your DNA Sequence Using Natural Language",
|
166 |
theme=gr.themes.Soft(),
|
|
|
1 |
+
from sentence_transformers import SentenceTransformer
|
2 |
+
from huggingface_hub import CommitScheduler
|
3 |
+
from datasets import Dataset
|
4 |
import gradio as gr
|
|
|
5 |
import pandas as pd
|
6 |
+
|
7 |
+
|
8 |
from parameter_extractor import ParameterExtractor
|
9 |
from DNAseq import DNAseq
|
10 |
+
from helper import list_at_index_0, list_at_index_1
|
11 |
+
from logger import cts_log_file_create, logger, cts_logger
|
12 |
+
|
13 |
+
# Create csv file for data logging
|
14 |
+
log_file_path = cts_log_file_create("flagged")
|
15 |
+
|
16 |
+
# Initialise CommitScheduler
|
17 |
+
scheduler = CommitScheduler(
|
18 |
+
repo_id="kevkev05/CTS-performance-metrics",
|
19 |
+
repo_type="dataset",
|
20 |
+
folder_path=log_file_path.parent,
|
21 |
+
path_in_repo="data",
|
22 |
+
every=5,
|
23 |
+
private=True,
|
24 |
+
)
|
25 |
|
26 |
def chat_to_sequence(sequence, user_query):
|
27 |
|
|
|
|
|
28 |
|
29 |
# Sequence to be analysed/queried
|
30 |
input_sequence = sequence
|
31 |
|
32 |
+
# Set DNAseq class expected variable
|
33 |
dna = input_sequence
|
34 |
|
35 |
# Model
|
|
|
126 |
proximal_upper_threshold,
|
127 |
]
|
128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
# Check the query score against threshold values
|
130 |
if query_score >= proximal_upper_threshold:
|
131 |
response = threshold_exceeded_message
|
132 |
+
cts_logger(scheduler, log_file_path, log_data, response)
|
133 |
print(threshold_exceeded_message)
|
134 |
|
135 |
elif proximal_lower_threshold < query_score < proximal_upper_threshold:
|
136 |
+
response = threshold_approximate_message + "\n" + ref_question
|
137 |
+
cts_logger(scheduler, log_file_path, log_data, response)
|
138 |
print(threshold_approximate_message, ref_question)
|
139 |
else:
|
140 |
print("Execute query")
|
|
|
149 |
function = matching_row.iloc[0]["function"]
|
150 |
response = str(eval(function))
|
151 |
code_descript_message = query_code_description.title()
|
152 |
+
cts_logger(scheduler, log_file_path, log_data, response)
|
153 |
else:
|
154 |
response = "Error processing query"
|
155 |
query_code = "No Match Error"
|
156 |
+
cts_logger(scheduler, log_file_path, log_data, response)
|
157 |
print("No matching code found for the function:", code)
|
158 |
|
159 |
return response, code_descript_message
|
|
|
165 |
inputs=[gr.Textbox(label="Sequence", placeholder="Input DNA Sequence..."),
|
166 |
gr.Textbox(label="Query", placeholder="Input Query...")],
|
167 |
outputs=[gr.Textbox(label="Response"), gr.Textbox(label="Action Executed")],
|
168 |
+
allow_flagging="never",
|
169 |
title="Chat-To-Sequence",
|
170 |
description="This Demo App Allows You To Explore Your DNA Sequence Using Natural Language",
|
171 |
theme=gr.themes.Soft(),
|
helper.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
import csv
|
2 |
-
import datetime
|
3 |
|
4 |
def list_at_index(extracted_list, index):
|
5 |
value_at_index = extracted_list[index]
|
@@ -17,18 +15,3 @@ def list_at_index_1(extracted_list):
|
|
17 |
value_at_index = extracted_list[1]
|
18 |
|
19 |
return value_at_index
|
20 |
-
|
21 |
-
def logger(log_filename, log_data, response):
|
22 |
-
with open(log_filename, mode='a', newline='') as log_file:
|
23 |
-
log_writer = csv.writer(log_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
24 |
-
|
25 |
-
# Get the current date and time
|
26 |
-
current_datetime = datetime.datetime.now()
|
27 |
-
date_str = current_datetime.strftime("%Y-%m-%d")
|
28 |
-
time_str = current_datetime.strftime("%H:%M:%S")
|
29 |
-
log_data.append(date_str)
|
30 |
-
log_data.append(time_str)
|
31 |
-
log_data.append(response)
|
32 |
-
# Write the log data to the CSV file
|
33 |
-
log_writer.writerow(log_data)
|
34 |
-
|
|
|
|
|
|
|
1 |
|
2 |
def list_at_index(extracted_list, index):
|
3 |
value_at_index = extracted_list[index]
|
|
|
15 |
value_at_index = extracted_list[1]
|
16 |
|
17 |
return value_at_index
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import datetime
|
3 |
+
import uuid
|
4 |
+
from pathlib import Path
|
5 |
+
|
6 |
+
|
7 |
+
def cts_logger(scheduler, log_filename, log_data, response) -> None:
|
8 |
+
with scheduler.lock:
|
9 |
+
logger(log_filename, log_data, response)
|
10 |
+
|
11 |
+
|
12 |
+
def logger(log_filename, log_data, response):
|
13 |
+
with open(log_filename, mode='a', newline='') as log_file:
|
14 |
+
log_writer = csv.writer(log_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
15 |
+
|
16 |
+
# Get the current date and time
|
17 |
+
current_datetime = datetime.datetime.now()
|
18 |
+
date_str = current_datetime.strftime("%Y-%m-%d")
|
19 |
+
time_str = current_datetime.strftime("%H:%M:%S")
|
20 |
+
log_data.append(date_str)
|
21 |
+
log_data.append(time_str)
|
22 |
+
log_data.append(response)
|
23 |
+
|
24 |
+
# Write the log data to the CSV file
|
25 |
+
log_writer.writerow(log_data)
|
26 |
+
|
27 |
+
|
28 |
+
def cts_log_file_create(folder_name):
|
29 |
+
file_path = Path(folder_name + "/") / f"CTS_user_log{uuid.uuid4()}.csv"
|
30 |
+
with open(file_path, mode='a', newline='') as log_file:
|
31 |
+
log_writer = csv.writer(log_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
32 |
+
|
33 |
+
headers = [
|
34 |
+
"user_query",
|
35 |
+
"ref_question",
|
36 |
+
"query_score",
|
37 |
+
"code_executed",
|
38 |
+
"ref_question_2",
|
39 |
+
"query_score_2",
|
40 |
+
"ref_question_3",
|
41 |
+
"query_score_3",
|
42 |
+
"similarity_metric",
|
43 |
+
"model_used_for_embeddings",
|
44 |
+
"lower_threshold",
|
45 |
+
"upper_threshold",
|
46 |
+
"date",
|
47 |
+
"time",
|
48 |
+
"response",
|
49 |
+
]
|
50 |
+
|
51 |
+
# Write headers to the CSV file
|
52 |
+
log_writer.writerow(headers)
|
53 |
+
|
54 |
+
return file_path
|