File size: 4,304 Bytes
0603825
 
 
d105155
616d63f
8b8af2d
 
7f9ca3b
b298f05
38ba92a
c5c5f4d
b298f05
38ba92a
2073913
8b8af2d
0603825
 
 
7d5cf5f
b298f05
8b8af2d
0603825
d105155
0603825
4eb6e09
616d63f
 
2073913
b298f05
 
 
 
 
 
 
41f4057
b298f05
0603825
b298f05
8b8af2d
 
 
 
2073913
0603825
 
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
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", "β›” Error: attesation failed"])
    POLICY = "./cce_policy.txt"
    if prompt == None:
        return (["β›” Error: please provide input code", "β›” 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: 900px !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()