whackthejacker commited on
Commit
15a59d8
·
verified ·
1 Parent(s): f8887f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -52
app.py CHANGED
@@ -1,60 +1,27 @@
1
  import gradio as gr
2
- from transformers import AutoModelForCausalLM, AutoTokenizer
3
- from datasets import load_dataset
 
4
 
5
- # Define model loading function
6
- def load_model(model_name):
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
- model = AutoModelForCausalLM.from_pretrained(model_name)
9
- return tokenizer, model
10
 
11
- # Load selected models
12
- models = {
13
- "bigcode/python-stack-v1-functions-filtered-sc2-subset": "bigcode/python-stack-v1-functions-filtered-sc2-subset",
14
- "bigcode/python-stack-v1-functions-filtered-sc2": "bigcode/python-stack-v1-functions-filtered-sc2",
15
- "muellerzr/python-stack-v1-functions-filtered-llama-3-8B": "muellerzr/python-stack-v1-functions-filtered-llama-3-8B",
16
- "TheBloke/Python-Code-13B-GGUF": "TheBloke/Python-Code-13B-GGUF",
17
- "replit/replit-code-v1_5-3b": "replit/replit-code-v1_5-3b",
18
- "neulab/codebert-python": "neulab/codebert-python"
19
- }
20
 
21
- # Load selected datasets
22
- datasets = {
23
- "kye/all-huggingface-python-code": "kye/all-huggingface-python-code",
24
- "ajibawa-2023/Python-Code-23k-ShareGPT": "ajibawa-2023/Python-Code-23k-ShareGPT",
25
- "suvadityamuk/huggingface-transformers-code-dataset": "suvadityamuk/huggingface-transformers-code-dataset"
26
- }
27
-
28
- # Define the function for code generation
29
- def generate_code(prompt, model_name, dataset_name, temperature, max_length):
30
- tokenizer, model = load_model(models[model_name])
31
-
32
- # Load dataset (for reference, not directly used)
33
- dataset = load_dataset(datasets[dataset_name], split="train")
34
-
35
- # Tokenize input prompt
36
- inputs = tokenizer(prompt, return_tensors="pt")
37
-
38
- # Generate output
39
- output_ids = model.generate(**inputs, temperature=temperature, max_length=max_length)
40
- generated_code = tokenizer.decode(output_ids[0], skip_special_tokens=True)
41
-
42
- return generated_code
43
-
44
- # Create Gradio Interface
45
  iface = gr.Interface(
46
- fn=generate_code,
47
- inputs=[
48
- gr.Textbox(label="Prompt"),
49
- gr.Dropdown(label="Model", choices=list(models.keys())),
50
- gr.Dropdown(label="Dataset", choices=list(datasets.keys())),
51
- gr.Slider(label="Temperature", minimum=0.1, maximum=1.0, value=0.5),
52
- gr.Slider(label="Max Length", minimum=10, maximum=1000, value=200)
53
  ],
54
- outputs="text",
55
- title="Ultimate Code Generator Python: AI Code Generator with Hugging Face Models",
56
- description="Select a model and dataset, input a prompt, and generate Python code using AI models."
57
  )
58
 
59
- # Launch the Gradio App
60
- iface.launch()
 
1
  import gradio as gr
2
+ from models.codet5 import CodeT5
3
+ from models.other_models import OtherModels
4
+ from repositories.github_api import GitHubAPI
5
 
6
+ codet5_model = CodeT5()
7
+ other_models = OtherModels()
8
+ github_api = GitHubAPI()
 
 
9
 
10
+ def analyze_repository(repo_url):
11
+ repo_data = github_api.get_repository(repo_url)
12
+ optimization_results = codet5_model.analyze(repo_data, github_api)
13
+ bug_hunting_results = other_models.analyze(repo_data, github_api)
14
+ return optimization_results, bug_hunting_results
 
 
 
 
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  iface = gr.Interface(
17
+ fn=analyze_repository,
18
+ inputs=gr.Textbox(lines=1, placeholder="Enter GitHub Repository URL (e.g., https://github.com/owner/repo)"),
19
+ outputs=[
20
+ gr.Textbox(lines=10, label="Optimization Results"),
21
+ gr.Textbox(lines=10, label="Bug Hunting Results"),
 
 
22
  ],
23
+ title="GitHub Repository Analyzer",
24
+ description="Analyze GitHub repositories for optimization suggestions and potential bugs using CodeT5 and other models.",
 
25
  )
26
 
27
+ iface.launch()