File size: 1,302 Bytes
9c3f77f
 
 
 
573c7b4
9c3f77f
573c7b4
9c3f77f
 
 
 
 
 
 
573c7b4
 
 
 
f9bbfe7
f1d11f4
573c7b4
9c3f77f
 
573c7b4
f1d11f4
 
 
 
813f2a4
86b65b5
59c76b8
b88350d
 
 
 
d0750e7
9c3f77f
 
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
import gradio as gr
import requests
import json
import pprint
import pandas as pd

def sar_alert(MESSAGE, API_KEY):
    url = "https://9byf8l4qzk.execute-api.eu-west-2.amazonaws.com/dev/sar-alert-container"
    payload = json.dumps({"message": MESSAGE})
    headers = {
    'Content-Type': 'application/json',
    'x-api-key': API_KEY
    }
    response = requests.request("POST", url, headers=headers, data=payload)
    output_data = json.loads(response.text)
    # 
    pprint.pprint(output_data)
    df_response = pd.json_normalize(output_data)
    print(df_response,df_response.columns)
    df_response = df_response[['output.SAR_requested', 'output.explanation']]
    return df_response, str(output_data)

iface = gr.Interface(
    fn=sar_alert, 
    inputs=[
        "text", 
        "text"], 
    outputs=[
        gr.outputs.Dataframe(headers=['SAR_Requested', 'Explanation'], type='pandas', label="Output"),
        gr.outputs.Textbox(label="Raw Output") 
            ],
    # examples=[
    #     ["Customer is asking about his data, and he is concerned about GDPR because he heard about it in the news.", "Private Key"],
    #     ["Hey Kate, save $50 when you spend $150 or more. Today only! Click here to see our new products (link).", "Private Key"],
    #         ]
    )

iface.launch()