Spaces:
Sleeping
Sleeping
File size: 4,497 Bytes
a9cc3c1 f6cf3fe 7985b10 fcffdd3 5456ae6 e5aa754 826501e e5aa754 c2d4ac9 e5aa754 d4c3a1a e5aa754 d4c3a1a e5aa754 d4c3a1a e5aa754 826501e e5aa754 826501e d4b5719 826501e fcffdd3 826501e fcffdd3 b52ce2e 826501e c51d3e3 4df8f3a 0cb6521 a9cc3c1 f6cf3fe e5aa754 c0c8c9d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
from fastapi import FastAPI, Request
import gradio as gr
from slack_bolt import App
from slack_bolt.adapter.fastapi import SlackRequestHandler
import os
import logging
from download_judgements import fetch_case_names, fetch_judgements
from interpret_judgement import interpret_judgement, interpret_by_case_title
from simple_kv_store import SimpleKVStore
from datetime import datetime
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
#### Gradio
io = gr.Interface(
fn=interpret_by_case_title,
inputs=[
gr.Dropdown(
fetch_case_names(), label="Select a judement", info="Select a case from latest Supreme Court judgements"
),
],
outputs=gr.Textbox(label="Judgement Summary"),
title="Judgement Buzz",
description="Judgement Buzz - Decoding complex Supreme Court rulings with ease.",
allow_flagging= "never"
)
### Slack
slack_app = App(token=os.environ.get("SLACK_BOT_TOKEN"),
signing_secret=os.environ.get("SLACK_SIGNING_SECRET"))
@slack_app.command("/get-case-digest")
def get_case_digest(ack, respond, command):
# Acknowledge command request
ack()
cases = fetch_judgements()
blocks = [
{
"type": "section",
"text": {"type": "mrkdwn", "text": f"Here are 5 recent judgements we found for you."},
},
{
"type": "section",
"text": {"type": "mrkdwn", "text": f"Click button `Summarize` to get quick summary of the judgement"},
},
{
"type": "divider"
},
]
for case in cases[:5]:
blocks = blocks + [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"*<{case['link']}| {case['title']}>*\n*Diary no*: {case['diary_no']}",
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Summarize",
"emoji": True
},
"value": case['diary_no'],
"action_id": "summarize_case"
}
},
{
"type": "divider"
},
]
# logging.info(blocks)
resp = respond(text=f"hello", blocks=blocks, response_type='in_channel')
@slack_app.action("summarize_case")
def handle_summarize_action(ack, action, respond):
ack()
case = SimpleKVStore.get(action['value'])
logging.info(f"Case retrieved {case}")
today = datetime.today().strftime("%Y-%m-%d")
summary = interpret_judgement(case['link'], case['diary_no'], case['title'])
blocks = [
{
"type": "header",
"text": {
"type": "plain_text",
"text": f":newspaper: {case['title']} :newspaper:"
}
},
{
"type": "context",
"elements": [
{
"text": f":calendar: *{today}*",
"type": "mrkdwn"
},
{
"text": "|",
"type": "mrkdwn"
},
{
"text": ":round_pushpin: New Delhi",
"type": "mrkdwn"
}
]
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": f"{summary}"
}
},
{
"type": "divider"
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": f":pushpin: Want to know more ? Click <{case['link']}|here> to access full court judgement."
}
]
}
]
respond(blocks=blocks, response_type='in_channel', replace_original=False, delete_original=False)
# main
app_handler = SlackRequestHandler(slack_app)
app = FastAPI()
app = gr.mount_gradio_app(app, io, path='/gradio')
@app.post("/slack/events")
async def endpoint(req: Request):
logging.info('recevied slack event')
return await app_handler.handle(req)
app.mount("/static", StaticFiles(directory="static", html=True), name="static")
@app.get("/")
async def root():
return FileResponse("static/index.html")
|