prometheus04 commited on
Commit
70be88c
·
verified ·
1 Parent(s): d1f9e51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py CHANGED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import LLaMAForCausalLM, LLaMATokenizer
4
+
5
+ # Load model and tokenizer
6
+ model_name = "llama-3.1"
7
+ tokenizer = LLaMATokenizer.from_pretrained(model_name)
8
+ model = LLaMAForCausalLM.from_pretrained(model_name)
9
+
10
+ # Define code analysis function
11
+ def analyze_code(code):
12
+ inputs = tokenizer.encode_plus(code, return_tensors="pt")
13
+ outputs = model.generate(inputs["input_ids"], max_length=512)
14
+ return outputs.last_hidden_state
15
+
16
+ # Define GitHub API function
17
+ def get_repo_code(repo_link):
18
+ GITHUB_TOKEN = "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"
19
+ GITHUB_API_URL = "https://api.github.com"
20
+ owner, repo = repo_link.split("/")[-2:]
21
+ repo_url = f"{GITHUB_API_URL}/repos/{owner}/{repo}/contents"
22
+ headers = {"Authorization": f"Bearer {GITHUB_TOKEN}"}
23
+ response = requests.get(repo_url, headers=headers)
24
+ return response.json()
25
+
26
+ # Create Gradio interface
27
+ demo = gr.Interface(
28
+ fn=analyze_code,
29
+ inputs=gr.Textbox(label="Enter code to analyze"),
30
+ outputs=gr.JSON(label="Analyzed code representation"),
31
+ title="Code Analysis with LLaMA 3.1",
32
+ description="Enter code to analyze and get its representation using LLaMA 3.1 model."
33
+ )
34
+
35
+ # Create Gradio interface for GitHub repository link
36
+ github_demo = gr.Interface(
37
+ fn=get_repo_code,
38
+ inputs=gr.Textbox(label="Enter GitHub repository link"),
39
+ outputs=gr.JSON(label="Repository code"),
40
+ title="Get GitHub Repository Code",
41
+ description="Enter GitHub repository link to get its code."
42
+ )
43
+
44
+ # Launch Gradio app
45
+ gr.TabbedInterface([demo, github_demo], ["Analyze Code", "Get Repository Code"]).launch()