thedamn commited on
Commit
2f21516
·
1 Parent(s): a2be3db

errors commitw

Browse files
Files changed (3) hide show
  1. app.py +40 -12
  2. proper_main.py +58 -39
  3. resource.py +8 -11
app.py CHANGED
@@ -1,25 +1,53 @@
 
1
  from resource import *
2
  from proper_main import *
3
- import streamlit as st
4
- import subprocess as sp
5
-
6
 
7
  def main():
8
- st.title("GPT4All Chatbot")
9
 
10
  # User input
11
  user_url = st.text_input("Enter the Github URL")
 
 
12
 
13
  # Generate response
14
  if st.button("Submit"):
15
- web_scrape(user_url)
16
- curr_path = data_cloning()
17
- query = analyse()
18
- llm_chain=langu()
19
- #response_gpt = llm_chain([str(query)])
20
- # Display the response
21
- #st.text_area("Bot Response:", value=response_gpt, height=100)
22
- st.text_area("Bot Response:", value=sp.check_output(['ls','-la','/tmp']), height=100)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
  if __name__ == "__main__":
25
  main()
 
 
1
+ import streamlit as st
2
  from resource import *
3
  from proper_main import *
4
+ from resource import llm_chain
5
+ import time
 
6
 
7
  def main():
8
+ st.title("Github Automated Repo Analysis")
9
 
10
  # User input
11
  user_url = st.text_input("Enter the Github URL")
12
+
13
+ option = st.radio("What you want me to do",["Python Analysis","GPT Evaluation"])
14
 
15
  # Generate response
16
  if st.button("Submit"):
17
+
18
+ st.text("Please wait Automation is Processing")
19
+ strttime=time.time()
20
+ repos, status = web_scrape(user_url,st)
21
+
22
+ #task_progress = st.progress(0)
23
+ #task_progress.progress("Tools is taking action please wait")
24
+ if status == 0:
25
+ repo_path = data_cloning(repos,st)
26
+ data_cleaning(repo_path,st)
27
+ query,report_analysis = analyse(st)
28
+ if len(query) == 0:
29
+ st.write("The given User's URL doesnt Contain Python Repository")
30
+ st.experimental_rerun()
31
+ if option == "Python Analysis":
32
+ repo_name,score=self_analysis(report_analysis)
33
+ output="The Complex Repo is "+ str(repo_name)+" Because the Complexity Score is "+str(score)
34
+ #st.write("The Complex Repo is",repo_name," Because the Complexity Score is",score)
35
+ st.text_area("Bot Response:", value=output, height=100)
36
+ time.sleep(15)
37
+ st.experimental_rerun()
38
+
39
+ elif option == "GPT Evaluation":
40
+ response_gpt = llm_chain([str(query)])
41
+ # Display the response
42
+ st.text_area("Bot Response:", value=response_gpt['text'], height=100)
43
+ elapsed_time = time.time() - strttime
44
+ st.text(f"Execution time: {elapsed_time:.2f} seconds")
45
+ else:
46
+ output = st.empty()
47
+ output.error("Error occurred. Please contact the admin {e}.")
48
+ time.sleep(5)
49
+ st.experimental_rerun()
50
 
51
  if __name__ == "__main__":
52
  main()
53
+
proper_main.py CHANGED
@@ -20,40 +20,39 @@ except Exception as e:
20
  os.system("pip install -r " + curr_dir + "/requirements.txt")
21
 
22
 
23
- repos = []
24
 
25
 
26
- def web_scrape(user_url):
27
- base_url = "https://www.github.com"
28
- user_url = user_url
29
-
30
- if user_url.endswith("/"):
31
- user_url = user_url[:-1]
32
-
33
- try:
34
- response = requests.get(user_url + "?tab=repositories")
35
- except Exception as e:
36
- print("Please provide a valid link:", e)
37
- web_scrape()
38
 
 
 
 
 
 
 
 
 
39
  if response.status_code != 200:
40
- print("Please provide a valid link.")
41
- web_scrape()
42
-
43
- make_soup = BeautifulSoup(response.text, 'html.parser')
44
- li = make_soup.findAll('div', class_='d-inline-block mb-1')
45
- if len(li) == 0:
46
- print("Please Provide the Valid Link")
47
- web_scrape()
48
-
49
- for _, i in enumerate(li):
50
- for a in i.findAll('a'):
51
- new_url = base_url + a['href']
52
- repos.append(new_url)
53
-
54
-
55
- def data_cloning():
 
56
  os.mkdir("/tmp/repos")
 
 
 
57
  os.chdir("/tmp/repos")
58
  for i in repos:
59
  sp.run(["git", "clone", i], stdout=sp.DEVNULL, stderr=sp.DEVNULL)
@@ -61,18 +60,23 @@ def data_cloning():
61
  return os.getcwd()
62
 
63
 
64
- def data_cleaning(directory):
65
  exporter = PythonExporter()
 
 
 
 
 
66
 
67
  for root, dirs, files in os.walk(directory, topdown=False):
68
  for filename in files:
69
  file_path = os.path.join(root, filename)
70
 
71
- if filename.endswith(".ipynb"):
72
- output, _ = exporter.from_filename(file_path)
73
- with open(os.path.join(root, filename[:-6] + ".py"), "w") as script_file:
74
- script_file.write(output)
75
- os.remove(file_path)
76
 
77
  if not (filename.endswith(".py") or filename.endswith(".ipynb")):
78
  os.remove(file_path)
@@ -83,19 +87,24 @@ def data_cleaning(directory):
83
  os.rmdir(dir_path)
84
 
85
 
86
- def analyse():
87
  project_and_grades = {}
 
 
 
 
 
88
 
89
  for file in os.listdir(os.getcwd()):
90
  print(file)
91
  path = os.getcwd() + "/" + file
92
 
93
- cmd = ["radon", "cc", "--total-average", file]
94
  res = sp.check_output(cmd)
95
  index = res.decode().find("Average")
96
  if index <= 0:
97
  grade = "A"
98
- score = 1
99
  else:
100
  grade = res.decode()[index:]
101
  score = grade[23:-1]
@@ -104,9 +113,19 @@ def analyse():
104
 
105
 
106
  project_and_grades["Repo " + file] = "Grade " + grade + " Score " + str(score)
 
107
  shutil.rmtree('/tmp/repos')
108
 
109
- return project_and_grades
 
 
 
 
 
 
 
 
 
110
 
111
 
112
 
 
20
  os.system("pip install -r " + curr_dir + "/requirements.txt")
21
 
22
 
 
23
 
24
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
+ def web_scrape(user_url,st):
27
+ username=user_url[19:]
28
+ if username.endswith("/"):
29
+ username=username[:-1]
30
+ print(username)
31
+ base_url = f"https://api.github.com/users/{username}/repos"
32
+
33
+ response = requests.get(base_url)
34
  if response.status_code != 200:
35
+ return ("Please provide a valid link.",1)
36
+ st.text("Extracting the Repos")
37
+ repos = []
38
+ repositories = response.json()
39
+ for repo in repositories:
40
+
41
+ repo_name = repo["name"]
42
+
43
+ repos.append(repo_name)
44
+ return repos,0
45
+
46
+
47
+ def data_cloning(repos,st):
48
+
49
+ if os.path.isdir("/tmp/repos"):
50
+ shutil.rmtree("/tmp/repos")
51
+
52
  os.mkdir("/tmp/repos")
53
+
54
+
55
+ st.text("Cloning the Repos")
56
  os.chdir("/tmp/repos")
57
  for i in repos:
58
  sp.run(["git", "clone", i], stdout=sp.DEVNULL, stderr=sp.DEVNULL)
 
60
  return os.getcwd()
61
 
62
 
63
+ def data_cleaning(directory,st):
64
  exporter = PythonExporter()
65
+ st.text("Cleaning the Repos")
66
+
67
+ if len(os.listdir(os.getcwd())) ==0:
68
+ st.text("Not a Valid Repo")
69
+ st.experimental_rerun()
70
 
71
  for root, dirs, files in os.walk(directory, topdown=False):
72
  for filename in files:
73
  file_path = os.path.join(root, filename)
74
 
75
+ #if filename.endswith(".ipynb"):
76
+ #output, _ = exporter.from_filename(file_path)
77
+ #with open(os.path.join(root, filename[:-6] + ".py"), "w") as script_file:
78
+ # script_file.write(output)
79
+ #os.remove(file_path)
80
 
81
  if not (filename.endswith(".py") or filename.endswith(".ipynb")):
82
  os.remove(file_path)
 
87
  os.rmdir(dir_path)
88
 
89
 
90
+ def analyse(st):
91
  project_and_grades = {}
92
+ report_analysis = {}
93
+ st.text("Analysing...")
94
+ if len(os.listdir(os.getcwd())) ==0:
95
+ st.text("Not a Valid Repo")
96
+ st.experimental_rerun()
97
 
98
  for file in os.listdir(os.getcwd()):
99
  print(file)
100
  path = os.getcwd() + "/" + file
101
 
102
+ cmd = ["radon", "cc", "--total-average","--include-ipynb", file]
103
  res = sp.check_output(cmd)
104
  index = res.decode().find("Average")
105
  if index <= 0:
106
  grade = "A"
107
+ score = 0.5
108
  else:
109
  grade = res.decode()[index:]
110
  score = grade[23:-1]
 
113
 
114
 
115
  project_and_grades["Repo " + file] = "Grade " + grade + " Score " + str(score)
116
+ report_analysis["Repo " + file] = [float(score)]
117
  shutil.rmtree('/tmp/repos')
118
 
119
+ return project_and_grades,report_analysis
120
+
121
+
122
+
123
+ def self_analysis(report_analysis):
124
+ score= max(report_analysis.values())
125
+ for keyss in report_analysis:
126
+ if report_analysis[keyss]==score:
127
+ repo = keyss
128
+ return repo,score
129
 
130
 
131
 
resource.py CHANGED
@@ -19,24 +19,21 @@ score Rank Risk
19
  31 - 40 E High - Complex block, alarming
20
  41+ F Very high - Error-prone, unstable block
21
 
22
- based on the score and rank you have to return only one most complex repo from report
23
-
24
- if the report Rank has similar scores and rank act accordingly
25
 
26
  Report: {question}
27
 
28
  Answer:"""
29
 
30
- def langu():
31
 
32
- import os
33
- prompt = PromptTemplate(template=template, input_variables=["question"])
 
 
 
 
34
 
35
- hf_hub_download(repo_id="dnato/ggml-gpt4all-j-v1.3-groovy.bin", filename="ggml-gpt4all-j-v1.3-groovy.bin", local_dir="/tmp")
36
- local_path= "/home/user/.cache/huggingface/hub/models--dnato--ggml-gpt4all-j-v1.3-groovy.bin/blobs/3b2fd7cca97284467de0be8f638925f40cbff4c70a2e10ba1094f83bfa24d86b"
37
- llm = GPT4All(model=local_path,callbacks=[StreamingStdOutCallbackHandler()] )
38
- llm_chain = LLMChain(prompt=prompt, llm=llm)
39
- return llm_chain
40
 
41
 
42
 
 
19
  31 - 40 E High - Complex block, alarming
20
  41+ F Very high - Error-prone, unstable block
21
 
22
+ based on the score and rank you have to return only one most complex repo which has more score from report
23
+ if all the repos are at the same rank and score choose randomly one
 
24
 
25
  Report: {question}
26
 
27
  Answer:"""
28
 
 
29
 
30
+ prompt = PromptTemplate(template=template, input_variables=["question"])
31
+
32
+ hf_hub_download(repo_id="dnato/ggml-gpt4all-j-v1.3-groovy.bin", filename="ggml-gpt4all-j-v1.3-groovy.bin", local_dir="/tmp")
33
+ local_path= os.getcwd() + "/ggml-gpt4all-j-v1.3-groovy.bin"
34
+ llm = GPT4All(model_name="ggml-gpt4all-j-v1.3-groovy",model_path="/tmp",callbacks=[StreamingStdOutCallbackHandler()] )
35
+ llm_chain = LLMChain(prompt=prompt, llm=llm)
36
 
 
 
 
 
 
37
 
38
 
39