File size: 1,276 Bytes
68ca8cd
fff49e6
 
68ca8cd
fff49e6
 
 
 
68ca8cd
9804479
fff49e6
 
 
 
 
 
316fef8
fff49e6
 
 
 
 
316fef8
fff49e6
68ca8cd
 
 
9804479
 
 
 
68ca8cd
 
 
 
fff49e6
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
import gradio as gr
from huggingface_hub import InferenceClient
import os

client = InferenceClient(
	provider="sambanova",
	api_key= os.getenv("superSecretKey")
)

def evaluate_code_security(code):
    messages = [
        {
            "role": "user",
            "content": f"You are BoxyReviewer. You work for OmniBlocks, a Python IDE. Your job is to review code before it is uploaded to the cloud. Not for bugs, that's the compiler's thing. Your job is to look at the code and make sure none of it is malicious before it gets to OmniBlocks' server. Your response must be formatted in a JSON format. The key 'result' should be either 'Safe' or 'Unsafe'. The key 'reason' should explain your reasoning. Here's the code {code}"
        }
    ]

    completion = client.chat.completions.create(
        model="meta-llama/Llama-3.1-8B-Instruct", 
        messages=messages, 
        max_tokens=500
    )

    response = completion.choices[0].message["content"]
    return response

demo = gr.Interface(
    evaluate_code_security,
    gr.Textbox(label="Enter your code"),
    gr.Textbox(label="Code Security Evaluation"),
    title="Code Security Evaluator",
    description="Get the AI's evaluation of your password strength.",
)

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