Spaces:
Sleeping
Sleeping
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() |