Spaces:
Build error
Build error
| 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() |