Spaces:
Runtime error
Runtime error
import gradio as gr | |
from blindbox.requests import SecureSession | |
DEMO_SERVER = "4.208.9.167:80" | |
text = "<h1 style='text-align: center; color: white;'>π SantaCoder with <span style='color: #f0ba2d;'>BlindBox:</span> Private Code Generation </h1><p style='text-align: left; color: white;'>This is our demo for our <a style='color: #f0ba2d;', href='https://blog-mithril-security.ghost.io/ai-assisted-code-generation-with-privacy-guarantees-securely-deploy-santacoder-with-blindbox'>article</a> on deploying code generation LLM models with BlindBox. The user input is <a style='color: #f0ba2d;', href='https://blindbox.mithrilsecurity.io/en/latest/docs/getting-started/confidential_computing/'>protected during computation</a> by leveraging state-of-the-art <a style='color: #f0ba2d;', href='https://www.ibm.com/topics/confidential-computing'> Confidental Computing technologies.</a> This means that data sent to Santacoder model is never accessible to the service provider during computation- private code remains private!</p><p style='text-align: left; color: white;'>You can see how we deployed the model in the integration section of our <a style='color: #f0ba2d;', href='https://blindbox.mithrilsecurity.io/en/latest/docs/how-to-guides/santacoder/'>documentation!</a></p><p style='text-align: left; color: white;'>β οΈ BlindBox is still under development. Do not test with production data!</p>" | |
bullets = "<ul><li style='color: white;'>β Connection verified by <a style='color: #f0ba2d;', href='https://blindbox.mithrilsecurity.io/en/latest/docs/security/attestation'>attestation</a></li><li style='color: white;'>β Application deployed on Confidential VM</li></ul><p style='color: white;'>Features coming soon:</p><ul><li style='color: white;'>β TLS</li><li style='color: white;'>β Network isolation</li></ul>" | |
token_info = "<p style='color: white;'> Find out more about the MAA attesation token <a style='color: #f0ba2d;', href='https://blindbox.mithrilsecurity.io/en/latest/docs/security/attestation/#maa-attestation-token'>here!</a>" | |
def run_query( server, prompt): | |
if server == "Non-confidential VM server": | |
return ("β Error: you can only connect to an application running on a Confidential VM") | |
POLICY = "./cce_policy.txt" | |
if prompt == None: | |
return ("β Error: please provide input code") | |
message = "\n\nβ Secure query succesful" | |
message2 = "β Attestation validated\n" | |
try: | |
with SecureSession(f"http://{DEMO_SERVER}", POLICY) as secure_session: | |
res = secure_session.post(endpoint="/generate", json={"input_text": prompt}) | |
cleaned = res.text.replace('\\n', '\n').split('\n\n')[0].split(':"')[1] | |
cleaned = cleaned.replace('\\', '') | |
return(cleaned + message, message2 + secure_session.jwt) | |
except Exception as err: | |
return(f"β Query failed!\n{err}") | |
demo = gr.Blocks(css=".gradio-container { background-color: #20233fff;} .app.svelte-1mya07g.svelte-1mya07g {max-width: 1100px !important;}") | |
with demo: | |
gr.Markdown(value=text) | |
gr.Markdown(value=bullets) | |
_, colum_2, _ = gr.Column(scale=1), gr.Column(scale=6), gr.Column(scale=1) | |
with colum_2: | |
prompt = gr.Code(lines=3, language="python", label="Input code", value="def hello_name(name):") | |
with gr.Accordion("Advanced settings", open=False): | |
server = gr.Radio( | |
["Authentic confidential VM server", "Non-confidential VM server"], label="Test connections to secure and insecure servers" | |
) | |
trigger = gr.Button(label="Run query") | |
with gr.Column(): | |
output = gr.Textbox(placeholder="Output", label="Output") | |
with gr.Accordion("Attestation token (signed JWT token): ", open=False): | |
output2 = gr.Textbox(placeholder="Attestation token", label="Output") | |
gr.Markdown(value=token_info) | |
trigger.click(fn=run_query, inputs=[server, prompt], outputs=[output, output2]) | |
gr.HTML(label="Contact", value="<img src='https://github.com/mithril-security/blindbox/blob/laura-images/docs/assets/contact-us.png?raw=true.png' alt='contact' style='display: block; margin: auto; max-width: 600px;'>") | |
if __name__ == "__main__": | |
demo.launch() | |