Spaces:
Runtime error
Runtime error
File size: 3,279 Bytes
0603825 d105155 2073913 0603825 7f9ca3b b298f05 41f4057 c5c5f4d b298f05 2073913 0603825 7d5cf5f b298f05 2073913 0603825 d105155 0603825 2073913 b298f05 2073913 a2f5c93 2073913 b298f05 41f4057 b298f05 0603825 b298f05 7f9ca3b 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 |
import gradio as gr
from blindbox.requests import SecureSession
DEMO_SERVER = "4.208.9.167:80"
bullets = "<ul><li style='color: white;'>β
Connection verified by attestation</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>"
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"
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)
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: 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></p>")
gr.Markdown("<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>")
gr.Markdown("<p style='text-align: left; color: white;'>β οΈ BlindBox is still under development. Do not test with production data!</p>")
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")
trigger.click(fn=run_query, inputs=[server, prompt], outputs=output)
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()
|