Spaces:
Runtime error
Runtime error
Adding logging of input/output to Notion
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from scipy.special import expit
|
|
3 |
import numpy as np
|
4 |
import os
|
5 |
import gradio as gr
|
|
|
6 |
|
7 |
# set up model
|
8 |
authtoken = os.environ.get("TOKEN") or True
|
@@ -27,9 +28,50 @@ def predict(text):
|
|
27 |
harm = sorted(harm, key=lambda x: x[1])[::-1][:1]
|
28 |
# top is the combo of these
|
29 |
top = issues + feelings + harm
|
|
|
|
|
|
|
30 |
d = {i: j for i, j in top}
|
31 |
return d
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
iface = gr.Interface(
|
34 |
fn=predict,
|
35 |
inputs="text",
|
|
|
3 |
import numpy as np
|
4 |
import os
|
5 |
import gradio as gr
|
6 |
+
import requests
|
7 |
|
8 |
# set up model
|
9 |
authtoken = os.environ.get("TOKEN") or True
|
|
|
28 |
harm = sorted(harm, key=lambda x: x[1])[::-1][:1]
|
29 |
# top is the combo of these
|
30 |
top = issues + feelings + harm
|
31 |
+
|
32 |
+
logToNotion(text, top)
|
33 |
+
|
34 |
d = {i: j for i, j in top}
|
35 |
return d
|
36 |
|
37 |
+
def logToNotion(text, top):
|
38 |
+
url = "https://api.notion.com/v1/pages"
|
39 |
+
|
40 |
+
payload = {
|
41 |
+
"properties": {
|
42 |
+
"title": {
|
43 |
+
"title": [{
|
44 |
+
"text": {
|
45 |
+
"content": "."
|
46 |
+
}
|
47 |
+
}]
|
48 |
+
},
|
49 |
+
"input": {
|
50 |
+
"rich_text": [{
|
51 |
+
"text": {
|
52 |
+
"content": text
|
53 |
+
}
|
54 |
+
}]
|
55 |
+
},
|
56 |
+
"output": {
|
57 |
+
"rich_text": [{
|
58 |
+
"text": {
|
59 |
+
"content": ", ".join(str(x) for x in top)
|
60 |
+
}
|
61 |
+
}]
|
62 |
+
}
|
63 |
+
},
|
64 |
+
"parent": "4a220773ac694851811e87f4571ec41d"
|
65 |
+
}
|
66 |
+
headers = {
|
67 |
+
"Accept": "application/json",
|
68 |
+
"Notion-Version": "2022-02-22",
|
69 |
+
"Content-Type": "application/json",
|
70 |
+
"Authorization": "Bearer secret_lc3Weq9s87EnkNWk2Yibko91hhLuNQIEzSoeAAoriUz"
|
71 |
+
}
|
72 |
+
|
73 |
+
response = requests.post(url, json=payload, headers=headers)
|
74 |
+
|
75 |
iface = gr.Interface(
|
76 |
fn=predict,
|
77 |
inputs="text",
|