File size: 2,948 Bytes
0603825
 
 
d105155
0603825
7f9ca3b
b298f05
41f4057
c5c5f4d
b298f05
 
0603825
 
 
7d5cf5f
b298f05
 
0603825
d105155
0603825
b298f05
 
 
 
 
 
 
 
 
 
 
 
 
41f4057
b298f05
0603825
b298f05
7f9ca3b
b298f05
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
import gradio as gr
from blindbox.requests import SecureSession

DEMO_SERVER = "4.208.9.167:80"

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")
    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 + "\n\nβœ… Input is end-to-end protected\nUser data is protected by a highly isolated and secure environment during runtime, meaning we, as the service providers, cannot access your input!")
    except Exception as err:
        return(f"β›” Query failed!\n{err}")

with gr.Blocks(css=".gradio-container {background-color: #20233fff}") as demo:
    gr.Markdown("<h1 style='text-align: center; color: white;'>πŸŽ… SantaCoder with <span style='color: #f0ba2d;'>BlindBox:</span> Private Code Generation </h1>")
    
    gr.Markdown("<p style='text-align: center; 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")
    gr.Markdown("<p style='text-align: center; color: white;'>The user input is <span style='color: #f0ba2d;'>end-to-end protected</span> with the user prompt processed in a highly isolated and secure environment</p>")
    gr.Markdown("<p style='text-align: center; 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!</p>")
    _, 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")
    trigger.click(fn=run_query, inputs=[server, prompt], outputs=output)
    gr.HTML(label="Contact", value="<img src='https://github.com/mithril-security/blindbox/blob/main/docs/assets/logo.png?raw=true.png' alt='contact' style='display: block; margin: auto; max-width: 200px;'>")

if __name__ == "__main__":
    demo.launch()