Santacoder-demo / app.py
lauro1's picture
updated text
c929fc3
raw
history blame
1.94 kB
import gradio as gr
from blindbox.requests import SecureSession
DEMO_SERVER = "4.208.9.167:80"
def run_query( prompt):
POLICY = "./cce_policy.txt"
if len(prompt) == 0:
return("⛔ Error: please add your query for automated code completion")
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]
return("✅ Query successful\n" + cleaned)
except Exception as err:
return(f"⛔ Query failed!\n{err}")
with gr.Blocks(theme=gr.themes.Soft()) as demo:
gr.Markdown("<h1><center>🔒Confidential code generation with BlindBox and Santacoder</center></h1>")
gr.Markdown("<p>This is the demo for our article on deploying code generation LLM models with BlindBox: <b>AI-assisted code generation with privacy guarantees: Securely deploy SantaCoder with BlindBox</b><br>You can view the article <a href='ai-assisted-code-generation-with-privacy-guarantees-securely-deploy-santacoder-with-blindbox'>here!</a> </p>")
gr.Markdown("<p>You can use this demo to send a function definition to BigCode's open-source Santacoder model and get back an auto-completed function.</p>")
gr.Markdown("<p>The model is deployed within a highly-isolated Trusted Execution Environment, meaning that we, as the service provider, have no access to the data sent to this model!</p>")
with gr.Column():
prompt = gr.Textbox(lines=2, placeholder="Enter function definition here e.g. def add_together(x,y):")
with gr.Column():
trigger = gr.Button("Test query")
with gr.Column():
output = gr.Textbox(placeholder="Output", label="See the output of your query here")
trigger.click(fn=run_query, inputs=[prompt], outputs=output)
if __name__ == "__main__":
demo.launch()