Spaces:
Runtime error
Runtime error
Create llama.py
Browse files
llama.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import LLaMAForCausalLM, LLaMATokenizer
|
3 |
+
|
4 |
+
model_name = "llama-3.1"
|
5 |
+
tokenizer = LLaMATokenizer.from_pretrained(model_name)
|
6 |
+
model = LLaMAForCausalLM.from_pretrained(model_name)
|
7 |
+
|
8 |
+
def analyze_code(code):
|
9 |
+
# Preprocess code for LLaMA 3.1
|
10 |
+
inputs = tokenizer.encode_plus(code, return_tensors="pt")
|
11 |
+
|
12 |
+
# Run code analysis using LLaMA 3.1
|
13 |
+
outputs = model.generate(inputs["input_ids"], max_length=512)
|
14 |
+
|
15 |
+
# Return analyzed code representation
|
16 |
+
return outputs.last_hidden_state
|