coeuslearning commited on
Commit
63ad984
1 Parent(s): 992e802

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -4
app.py CHANGED
@@ -1,7 +1,8 @@
1
  import os
2
  from threading import Thread
3
  from typing import Iterator
4
-
 
5
  import gradio as gr
6
  import spaces
7
  import torch
@@ -75,10 +76,30 @@ def generate(
75
  # yield "".join(outputs)
76
  yield masked_output
77
 
78
-
79
- def mask_with_protecto(msg_to_mask):
80
- return(msg_to_mask)
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  chat_interface = gr.ChatInterface(
84
  fn=generate,
 
1
  import os
2
  from threading import Thread
3
  from typing import Iterator
4
+ import requests
5
+ import json
6
  import gradio as gr
7
  import spaces
8
  import torch
 
76
  # yield "".join(outputs)
77
  yield masked_output
78
 
 
 
 
79
 
80
+ def mask_with_protecto(text_for_prompt):
81
+ mask_request_url = "https://trial.protecto.ai/api/vault/mask"
82
+ headers = {
83
+ "Content-Type": "application/json; charset=utf-8",
84
+ "Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3N1ZXIiOiJQcm90ZWN0byIsImV4cGlyYXRpb25fZGF0ZSI6IjIwMjMtMTEtMDQiLCJwZXJtaXNzaW9ucyI6WyJyZWFkIiwid3JpdGUiXSwidXNlcl9uYW1lIjoiZGlwYXlhbkBjb2V1c2xlYXJuaW5nLmNvbSIsImRiX25hbWUiOiJwcm90ZWN0b19jb2V1c2xlYXJuaW5nX25ydG1mYmFrIiwiaGFzaGVkX3Bhc3N3b3JkIjoiMjIyMTI2ZWNiZTlkZTRmNWJlODdiY2QyYWFlZWRlM2FmNDc5MzMxZmNhOTUxMWU0MDRiNzkxNDM1MGI4MWUyYiJ9.DeIK00NuhM51lRwWdnUXuQSBA1aBn5AQ8qM3pIeM01U"
85
+ }
86
+ mask_input = {
87
+ "mask": [
88
+ {
89
+ "value": text_for_prompt
90
+ }
91
+ ]
92
+ }
93
+ response = requests.put(mask_request_url, headers=headers, json=mask_input)
94
+ if response.status_code == 200:
95
+ # Parse the masked result from the API response and format it for display
96
+ masked_result = response.json()
97
+ final_result = json.dumps(masked_result, indent=4)
98
+ return(masked_result["data"][0]["token_value"])
99
+ else:
100
+ # Print an error message if the API request was not successful.
101
+ print(f"Failed to get a successful response. Status Code: {response.status_code}")
102
+ print(response.text)
103
 
104
  chat_interface = gr.ChatInterface(
105
  fn=generate,