Spaces:
Build error
Build error
Commit
·
d28511c
1
Parent(s):
7a3769b
Changes for output dataset
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from datasets import load_dataset, Dataset, DatasetDict
|
|
7 |
import pandas as pd
|
8 |
import re
|
9 |
import requests
|
|
|
10 |
API_ENDPOINT = "https://api.collinear.ai"
|
11 |
API_KEY = os.getenv("COLLINEAR_API_KEY")
|
12 |
HF_TOKEN=os.getenv("HF_TOKEN")
|
@@ -56,15 +57,15 @@ def classify_prompt(category,conv_prefix, response):
|
|
56 |
else:
|
57 |
return 'Unsafe'
|
58 |
|
59 |
-
async def add_to_dataset(conv_prefix, response,llama_resp,collinear_resp):
|
60 |
conv_prefix = json.loads(conv_prefix)
|
61 |
-
dataset = load_dataset("collinear-ai/collinear-guard-demo")
|
62 |
-
new_row = {'
|
63 |
-
'unsafe_text':"",
|
64 |
'conv_prefix':conv_prefix,
|
65 |
'response':response,
|
66 |
'llama_resp':{"output":llama_resp},
|
67 |
-
'collinear_resp':collinear_resp
|
|
|
68 |
}
|
69 |
train_dataset = dataset['train']
|
70 |
|
@@ -77,7 +78,7 @@ async def add_to_dataset(conv_prefix, response,llama_resp,collinear_resp):
|
|
77 |
updated_dataset = DatasetDict({
|
78 |
'train': new_train_dataset
|
79 |
})
|
80 |
-
updated_dataset.push_to_hub("collinear-ai/collinear-guard-demo",token=HF_TOKEN)
|
81 |
|
82 |
|
83 |
|
@@ -179,7 +180,7 @@ with gr.Blocks() as demo:
|
|
179 |
outputs=[collinear_output, llama_output]
|
180 |
).then(
|
181 |
fn=add_to_dataset,
|
182 |
-
inputs=[conv_prefix, response, llama_output, collinear_output],
|
183 |
outputs=[]
|
184 |
)
|
185 |
|
|
|
7 |
import pandas as pd
|
8 |
import re
|
9 |
import requests
|
10 |
+
from datetime import datetime
|
11 |
API_ENDPOINT = "https://api.collinear.ai"
|
12 |
API_KEY = os.getenv("COLLINEAR_API_KEY")
|
13 |
HF_TOKEN=os.getenv("HF_TOKEN")
|
|
|
57 |
else:
|
58 |
return 'Unsafe'
|
59 |
|
60 |
+
async def add_to_dataset(category,conv_prefix, response,llama_resp,collinear_resp):
|
61 |
conv_prefix = json.loads(conv_prefix)
|
62 |
+
dataset = load_dataset("collinear-ai/collinear-guard-safety-demo")
|
63 |
+
new_row = {'category':category,
|
|
|
64 |
'conv_prefix':conv_prefix,
|
65 |
'response':response,
|
66 |
'llama_resp':{"output":llama_resp},
|
67 |
+
'collinear_resp':collinear_resp,
|
68 |
+
"timestamp":datetime.now()
|
69 |
}
|
70 |
train_dataset = dataset['train']
|
71 |
|
|
|
78 |
updated_dataset = DatasetDict({
|
79 |
'train': new_train_dataset
|
80 |
})
|
81 |
+
updated_dataset.push_to_hub("collinear-ai/collinear-guard-safety-demo",token=HF_TOKEN)
|
82 |
|
83 |
|
84 |
|
|
|
180 |
outputs=[collinear_output, llama_output]
|
181 |
).then(
|
182 |
fn=add_to_dataset,
|
183 |
+
inputs=[category,conv_prefix, response, llama_output, collinear_output],
|
184 |
outputs=[]
|
185 |
)
|
186 |
|