sergeyfeldman commited on
Commit
e8be0f0
·
1 Parent(s): aa85032

no more logging to notion + return all issues/feelings

Browse files
Files changed (1) hide show
  1. app.py +3 -45
app.py CHANGED
@@ -25,58 +25,16 @@ def predict(text):
25
  harm = [(i, j) for i, j in zipped_list if i.startswith('harm')]
26
  sentiment = [(i, j) for i, j in zipped_list if i.startswith('sentiment')]
27
  # keep tops for each one
28
- issues = sorted(issues, key=lambda x: x[1])[::-1][:3]
29
- feelings = sorted(feelings, key=lambda x: x[1])[::-1][:3]
30
  harm = sorted(harm, key=lambda x: x[1])[::-1]
31
- sentiment = sorted(sentiment, key=lambda x: x[1])[::-1][:1]
32
  # top is the combo of these
33
  top = issues + feelings + harm + sentiment
34
 
35
- logToNotion(text, top)
36
- # just anything to trigger a rebuild!
37
-
38
  d = {i: j for i, j in top}
39
  return d
40
 
41
- def logToNotion(text, top):
42
- url = "https://api.notion.com/v1/pages"
43
-
44
- payload = {
45
- "parent": {
46
- "database_id": "4a220773ac694851811e87f4571ec41d"
47
- },
48
- "properties": {
49
- "title": {
50
- "title": [{
51
- "text": {
52
- "content": datetime.now().strftime("%m/%d/%Y %H:%M:%S")
53
- }
54
- }]
55
- },
56
- "input": {
57
- "rich_text": [{
58
- "text": {
59
- "content": text
60
- }
61
- }]
62
- },
63
- "output": {
64
- "rich_text": [{
65
- "text": {
66
- "content": ", ".join(str(x) for x in top)
67
- }
68
- }]
69
- }
70
- }
71
- }
72
- headers = {
73
- "Accept": "application/json",
74
- "Notion-Version": "2022-02-22",
75
- "Content-Type": "application/json",
76
- "Authorization": "Bearer " + os.environ.get("NotionToken")
77
- }
78
-
79
- response = requests.post(url, json=payload, headers=headers)
80
 
81
  iface = gr.Interface(
82
  fn=predict,
 
25
  harm = [(i, j) for i, j in zipped_list if i.startswith('harm')]
26
  sentiment = [(i, j) for i, j in zipped_list if i.startswith('sentiment')]
27
  # keep tops for each one
28
+ issues = sorted(issues, key=lambda x: x[1])[::-1]
29
+ feelings = sorted(feelings, key=lambda x: x[1])[::-1]
30
  harm = sorted(harm, key=lambda x: x[1])[::-1]
31
+ sentiment = sorted(sentiment, key=lambda x: x[1])[::-1]
32
  # top is the combo of these
33
  top = issues + feelings + harm + sentiment
34
 
 
 
 
35
  d = {i: j for i, j in top}
36
  return d
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  iface = gr.Interface(
40
  fn=predict,