Spaces:
Build error
Build error
initial Commit
Browse files- Dockerfile +22 -0
- app.py +54 -0
- proper_main.py +141 -0
- requirements.txt +9 -0
- resource.py +40 -0
Dockerfile
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use an official Ubuntu base image
|
2 |
+
FROM kalilinux/kali-rolling
|
3 |
+
|
4 |
+
WORKDIR /code
|
5 |
+
|
6 |
+
COPY . /code
|
7 |
+
# Update the package lists
|
8 |
+
RUN apt-get update
|
9 |
+
|
10 |
+
# Install system packages
|
11 |
+
RUN apt-get install -y grep git python3 python3-pip coreutils curl
|
12 |
+
|
13 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
14 |
+
|
15 |
+
# Copy the rest of your application files
|
16 |
+
|
17 |
+
RUN curl -O https://gpt4all.io/models/ggml-gpt4all-j-v1.3-groovy.bin
|
18 |
+
|
19 |
+
EXPOSE 7860
|
20 |
+
|
21 |
+
CMD ["streamlit", "run", "app.py","--server.port", "7860"]
|
22 |
+
|
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
while True:
|
9 |
+
st.title("Github Automated Repo Analysis")
|
10 |
+
|
11 |
+
# User input
|
12 |
+
user_url = st.text_input("Enter the Github URL")
|
13 |
+
|
14 |
+
option = st.radio("What you want me to do",["Python Analysis","GPT Evaluation"])
|
15 |
+
|
16 |
+
# Generate response
|
17 |
+
if st.button("Submit"):
|
18 |
+
|
19 |
+
st.text("Please wait Automation is Processing")
|
20 |
+
strttime=time.time()
|
21 |
+
repos, status = web_scrape(user_url,st)
|
22 |
+
|
23 |
+
#task_progress = st.progress(0)
|
24 |
+
#task_progress.progress("Tools is taking action please wait")
|
25 |
+
if status == 0:
|
26 |
+
repo_path = data_cloning(repos,st)
|
27 |
+
data_cleaning(repo_path,st)
|
28 |
+
query,report_analysis = analyse(st)
|
29 |
+
if len(query) == 0:
|
30 |
+
st.write("The given User's URL doesnt Contain Python Repository")
|
31 |
+
break
|
32 |
+
if option == "Python Analysis":
|
33 |
+
repo_name,score=self_analysis(report_analysis)
|
34 |
+
output="The Complex Repo is "+ str(repo_name)+" Because the Complexity Score is "+str(score)
|
35 |
+
#st.write("The Complex Repo is",repo_name," Because the Complexity Score is",score)
|
36 |
+
st.text_area("Bot Response:", value=output, height=100)
|
37 |
+
time.sleep(15)
|
38 |
+
break
|
39 |
+
|
40 |
+
elif option == "GPT Evaluation":
|
41 |
+
response_gpt = llm_chain([str(query)])
|
42 |
+
# Display the response
|
43 |
+
st.text_area("Bot Response:", value=response_gpt['text'], height=100)
|
44 |
+
elapsed_time = time.time() - strttime
|
45 |
+
st.text(f"Execution time: {elapsed_time:.2f} seconds")
|
46 |
+
else:
|
47 |
+
output = st.empty()
|
48 |
+
output.error(f"Error occurred. Please contact the admin {repos}.")
|
49 |
+
time.sleep(5)
|
50 |
+
break
|
51 |
+
|
52 |
+
if __name__ == "__main__":
|
53 |
+
main()
|
54 |
+
|
proper_main.py
ADDED
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
try:
|
2 |
+
import requests
|
3 |
+
import os
|
4 |
+
import subprocess as sp
|
5 |
+
from bs4 import BeautifulSoup
|
6 |
+
from nbconvert import PythonExporter
|
7 |
+
import shutil
|
8 |
+
|
9 |
+
except Exception as e:
|
10 |
+
print("Some modules are missing:", e)
|
11 |
+
print("Do you want to install them via this Python program?")
|
12 |
+
option = input("Y or N: ")
|
13 |
+
if option.lower() not in ["y", "n"]:
|
14 |
+
exit()
|
15 |
+
elif option.lower() == "n":
|
16 |
+
exit()
|
17 |
+
elif option.lower() == "y":
|
18 |
+
print("Make sure your internet connection is active; otherwise, it may throw an error. Press 'N' to exit.")
|
19 |
+
curr_dir = os.getcwd()
|
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("https://github.com/"+username + "/" +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)
|
59 |
+
|
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 |
+
return
|
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)
|
83 |
+
|
84 |
+
for dir_name in dirs:
|
85 |
+
dir_path = os.path.join(root, dir_name)
|
86 |
+
if not os.listdir(dir_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 |
+
return
|
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]
|
111 |
+
score = score[:3]
|
112 |
+
grade=grade[20]
|
113 |
+
|
114 |
+
|
115 |
+
project_and_grades["Repo " + file] = " 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 |
+
|
132 |
+
"""def main():
|
133 |
+
web_scrape()
|
134 |
+
curr_path=data_cloning()
|
135 |
+
data_cleaning(curr_path)
|
136 |
+
report=analyse()
|
137 |
+
print(report)
|
138 |
+
|
139 |
+
if __name__ == main():
|
140 |
+
main()
|
141 |
+
"""
|
requirements.txt
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
gpt4all
|
3 |
+
langchain
|
4 |
+
huggingface
|
5 |
+
huggingface_hub
|
6 |
+
radon
|
7 |
+
requests
|
8 |
+
bs4
|
9 |
+
nbconvert
|
resource.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain import PromptTemplate, LLMChain
|
2 |
+
from huggingface_hub import hf_hub_download
|
3 |
+
from langchain.llms import GPT4All
|
4 |
+
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
5 |
+
import os
|
6 |
+
|
7 |
+
|
8 |
+
template ="""
|
9 |
+
You are a friendly chatbot assistant you are going to evaluate a Github Repo i analysed all the repos and made a report
|
10 |
+
i'm gonna give a report you just refer the below table
|
11 |
+
|
12 |
+
Table:
|
13 |
+
|
14 |
+
score Risk
|
15 |
+
1 - 5 Low - Simple block
|
16 |
+
6 - 10 Low - Well structured and stable block
|
17 |
+
11 - 20 Moderate - Slightly complex block
|
18 |
+
21 - 30 More than moderate - More complex block
|
19 |
+
31 - 40 High - Complex block, alarming
|
20 |
+
41+ Very high - Error-prone, unstable block
|
21 |
+
|
22 |
+
based on the score and you have to return only one most complex repo which has more score from report
|
23 |
+
when the score is high thats the complex repo and
|
24 |
+
if all the repos are at the same score choose randomly one
|
25 |
+
|
26 |
+
Report: {question}
|
27 |
+
|
28 |
+
Answer:"""
|
29 |
+
|
30 |
+
|
31 |
+
prompt = PromptTemplate(template=template, input_variables=["question"])
|
32 |
+
|
33 |
+
#hf_hub_download(repo_id="dnato/ggml-gpt4all-j-v1.3-groovy.bin", filename="ggml-gpt4all-j-v1.3-groovy.bin", local_dir="/code")
|
34 |
+
local_path= os.getcwd() + "/ggml-gpt4all-j-v1.3-groovy.bin"
|
35 |
+
llm = GPT4All(model=local_path,callbacks=[StreamingStdOutCallbackHandler()] )
|
36 |
+
llm_chain = LLMChain(prompt=prompt, llm=llm)
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|