Ismael1-2-3 commited on
Commit
fff49e6
·
verified ·
1 Parent(s): 06bddba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -1,23 +1,27 @@
1
  import gradio as gr
2
- import torch
3
- from transformers import AutoModelForCausalLM, AutoTokenizer
4
 
5
- # Load the model and tokenizer
6
- model_name = "meta-llama/Llama-3.1-8B-Instruct"
7
- model = AutoModelForCausalLM.from_pretrained(model_name)
8
- tokenizer = AutoTokenizer.from_pretrained(model_name)
9
 
10
  def evaluate_code_security(code):
11
- # Prepare the input
12
- input_text = 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}"
13
- inputs = tokenizer(input_text, return_tensors="pt")
14
-
15
- # Run the model
16
- outputs = model.generate(**inputs, max_length=500)
17
 
18
- # Convert the output to text
19
- response = tokenizer.decode(outputs[0], skip_special_tokens=True)
 
 
 
20
 
 
21
  return response
22
 
23
  demo = gr.Interface(
@@ -29,4 +33,4 @@ demo = gr.Interface(
29
  )
30
 
31
  if __name__ == "__main__":
32
- demo.launch()
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+ import os
4
 
5
+ client = InferenceClient(
6
+ provider="sambanova",
7
+ api_key= os.getenv("superSecretKey")
8
+ )
9
 
10
  def evaluate_code_security(code):
11
+ messages = [
12
+ {
13
+ "role": "user",
14
+ "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}"
15
+ }
16
+ ]
17
 
18
+ completion = client.chat.completions.create(
19
+ model="meta-llama/Llama-3.1-8B-Instruct",
20
+ messages=messages,
21
+ max_tokens=500
22
+ )
23
 
24
+ response = completion.choices[0].message["content"]
25
  return response
26
 
27
  demo = gr.Interface(
 
33
  )
34
 
35
  if __name__ == "__main__":
36
+ demo.launch()