Spaces:
Sleeping
Sleeping
Atharva Chauthaiwale
commited on
Commit
·
fcffdd3
1
Parent(s):
4df8f3a
Slack app fix
Browse files
main.py
CHANGED
@@ -6,6 +6,8 @@ import os
|
|
6 |
import logging
|
7 |
from download_judgements import fetch_case_names, fetch_judgements
|
8 |
from interpret_judgement import interpret_judgement, interpret_by_case_title
|
|
|
|
|
9 |
|
10 |
#### Gradio
|
11 |
io = gr.Interface(
|
@@ -56,7 +58,7 @@ def get_case_digest(ack, respond, command):
|
|
56 |
"type": "button",
|
57 |
"text": {
|
58 |
"type": "plain_text",
|
59 |
-
"text": "
|
60 |
"emoji": True
|
61 |
},
|
62 |
"value": case['diary_no'],
|
@@ -70,6 +72,65 @@ def get_case_digest(ack, respond, command):
|
|
70 |
# logging.info(blocks)
|
71 |
resp = respond(text=f"hello", blocks=blocks, response_type='in_channel')
|
72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
app_handler = SlackRequestHandler(slack_app)
|
74 |
|
75 |
app = FastAPI()
|
|
|
6 |
import logging
|
7 |
from download_judgements import fetch_case_names, fetch_judgements
|
8 |
from interpret_judgement import interpret_judgement, interpret_by_case_title
|
9 |
+
from simple_kv_store import SimpleKVStore
|
10 |
+
from datetime import datetime
|
11 |
|
12 |
#### Gradio
|
13 |
io = gr.Interface(
|
|
|
58 |
"type": "button",
|
59 |
"text": {
|
60 |
"type": "plain_text",
|
61 |
+
"text": "Summarize",
|
62 |
"emoji": True
|
63 |
},
|
64 |
"value": case['diary_no'],
|
|
|
72 |
# logging.info(blocks)
|
73 |
resp = respond(text=f"hello", blocks=blocks, response_type='in_channel')
|
74 |
|
75 |
+
@slack_app.action("summarize_case")
|
76 |
+
def handle_summarize_action(ack, action, respond):
|
77 |
+
ack()
|
78 |
+
case = SimpleKVStore.get(action['value'])
|
79 |
+
logging.info(f"Case retrieved {case}")
|
80 |
+
today = datetime.today().strftime("%Y-%m-%d")
|
81 |
+
summary = interpret_judgement(case['link'], case['diary_no'], case['title'])
|
82 |
+
blocks = [
|
83 |
+
{
|
84 |
+
"type": "header",
|
85 |
+
"text": {
|
86 |
+
"type": "plain_text",
|
87 |
+
"text": f":newspaper: {case['title']} :newspaper:"
|
88 |
+
}
|
89 |
+
},
|
90 |
+
{
|
91 |
+
"type": "context",
|
92 |
+
"elements": [
|
93 |
+
{
|
94 |
+
"text": f":calendar: *{today}*",
|
95 |
+
"type": "mrkdwn"
|
96 |
+
},
|
97 |
+
{
|
98 |
+
"text": "|",
|
99 |
+
"type": "mrkdwn"
|
100 |
+
},
|
101 |
+
{
|
102 |
+
"text": ":round_pushpin: New Delhi",
|
103 |
+
"type": "mrkdwn"
|
104 |
+
}
|
105 |
+
]
|
106 |
+
},
|
107 |
+
{
|
108 |
+
"type": "divider"
|
109 |
+
},
|
110 |
+
{
|
111 |
+
"type": "section",
|
112 |
+
"text": {
|
113 |
+
"type": "mrkdwn",
|
114 |
+
"text": f"{summary}"
|
115 |
+
}
|
116 |
+
},
|
117 |
+
{
|
118 |
+
"type": "divider"
|
119 |
+
},
|
120 |
+
{
|
121 |
+
"type": "context",
|
122 |
+
"elements": [
|
123 |
+
{
|
124 |
+
"type": "mrkdwn",
|
125 |
+
"text": f":pushpin: Want to know more ? Click <{case['link']}|here> to access full court judgement."
|
126 |
+
}
|
127 |
+
]
|
128 |
+
}
|
129 |
+
]
|
130 |
+
|
131 |
+
respond(blocks=blocks, response_type='in_channel', replace_original=False, delete_original=False)
|
132 |
+
|
133 |
+
# main
|
134 |
app_handler = SlackRequestHandler(slack_app)
|
135 |
|
136 |
app = FastAPI()
|