Skip to content

Commit 1fed672

Browse files
authored
Merge pull request #182 from manikumarreddyu/automated
Github-Automated-Analysis
2 parents f27e3bf + f34f552 commit 1fed672

File tree

5 files changed

+447
-0
lines changed

5 files changed

+447
-0
lines changed

Github-Automated-Analysis/.gitignore

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
#.idea/
161+
162+
163+
.vscode
164+
.streamlit

Github-Automated-Analysis/main.py

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
import streamlit as st
2+
import requests
3+
import os
4+
from dotenv import load_dotenv
5+
import pandas as pd
6+
from langchain.embeddings.openai import OpenAIEmbeddings
7+
from langchain.prompts import PromptTemplate
8+
from langchain.document_loaders import CSVLoader,TextLoader,DirectoryLoader
9+
from langchain.text_splitter import CharacterTextSplitter
10+
from langchain.chains import RetrievalQA
11+
from langchain.llms import OpenAI
12+
from langchain.vectorstores import FAISS
13+
import utils.config as config
14+
from github import Github
15+
from utils.constants import *
16+
17+
load_dotenv()
18+
os.environ['OPENAI_API_KEY'] = os.getenv('OPENAI_API_KEY')
19+
os.environ['GITHUB_TOKEN'] = os.getenv('GITHUB_TOKEN')
20+
os.environ['ACTIVELOOP_TOKEN'] = os.getenv('ACTIVELOOP_TOKEN')
21+
22+
23+
24+
st.set_page_config(page_title="GitHub Repositories List" , page_icon=":computer:" , layout="wide" , initial_sidebar_state="expanded")
25+
26+
27+
28+
29+
# Function to fetch GitHub repositories
30+
@st.cache_data # Cache data so that we don't have to fetch it again
31+
def fetch_github_repos(username):
32+
# url = f'https://api.github.com/users/{username}/repos'
33+
# response = requests.get(url)
34+
# if response.status_code == 200:
35+
# return response.json()
36+
# else:
37+
# return None
38+
repos = []
39+
page = 1
40+
while True:
41+
url = f"https://api.github.com/users/{username}/repos?page={page}&per_page=50"
42+
response = requests.get(url)
43+
data = response.json()
44+
if not data:
45+
break
46+
repos.extend([(repo) for repo in data])
47+
page += 1
48+
return repos
49+
50+
# Function to display repositories
51+
def display_repos(repos):
52+
for repo in repos:
53+
repo_name = repo["name"]
54+
repo_url = repo["html_url"]
55+
st.write(f"[{repo_name}]({repo_url})")
56+
57+
58+
59+
def get_user_repos(username):
60+
"""Gets the repository information of each of the repositories of a GitHub user.
61+
62+
Args:
63+
username: The username of the GitHub user.
64+
65+
Returns:
66+
A list of dictionaries, where each dictionary contains the information of a repository.
67+
"""
68+
client = Github()
69+
70+
user = client.get_user(username)
71+
repos = user.get_repos()
72+
73+
repo_info = []
74+
75+
for repo in repos:
76+
77+
repo_info.append({
78+
"name": repo.name,
79+
"description": repo.description,
80+
"language": repo.language,
81+
"stars": repo.stargazers_count,
82+
"forks": repo.forks_count,
83+
"labels": repo.get_labels(),
84+
"issues": repo.get_issues(state="all"),
85+
"contents" : repo.get_contents(""),
86+
87+
})
88+
89+
repo_info_df = pd.DataFrame(repo_info)
90+
repo_info_df.to_csv("repo_data.csv")
91+
92+
loader = CSVLoader(file_path="repo_data.csv", encoding ="utf-8")
93+
csv_data = loader.load()
94+
csv_embeddings = OpenAIEmbeddings()
95+
vectors = FAISS.from_documents(csv_data, csv_embeddings)
96+
97+
# Create a question-answering chain using the index
98+
99+
context = """ You are Supersmart Github Repository AI system. You are a superintelligent AI that answers questions about Github Repositories and can understand the technical complexity if the repo.
100+
101+
You are:
102+
- helpful & friendly
103+
- good at answering complex questions in simple language
104+
- an expert in all programming languages
105+
- able to infer the intent of the user's question
106+
107+
108+
Remember You are an inteelligent CSV Agent who can understand CSV files and their contents. You are given a CSV file with the following columns: Repository Name, Repository Link, Analysis. You are asked to find the most technically complex and challenging repository from the given CSV file.
109+
110+
To measure the technical complexity of a GitHub repository using the provided API endpoints, You will analyze various factors such as the number of commits, branches, pull requests, issues,contents , number of forks , stars , and contributors. Additionally, you will consider the programming languages used, the size of the codebase, and the frequency of updates.
111+
You will Analyze the following GitHub repository factors to determine the technical complexity of the codebase and calculate a complexity score for each project:
112+
113+
1.Description
114+
2.languages used in the repository
115+
3.Number of stars
116+
4.Number of forks
117+
5.Labels of the repository
118+
6.Description of the repository
119+
7.Contents of the repository
120+
121+
You can consider other factors as well if you think they are relevant for determining the technical complexity of a GitHub repository.
122+
Calculate the complexity score for each project by assigning weights to each factor and summing up the weighted scores.
123+
124+
The project with the highest complexity score will be considered the most technically complex.
125+
126+
Here is the approach or chain-of-thought process , you can use to reach to the solution :
127+
Step 1: Analyze each row and it's contents in the CSV file , each Row represents a Github Repository
128+
129+
130+
131+
"""
132+
133+
prompt_template = """
134+
135+
Understand the following to answer the question in an efficient way
136+
137+
{context}
138+
139+
Question: {question}
140+
Now answer the question. Let's think step by step:"""
141+
PROMPT = PromptTemplate(
142+
template=prompt_template, input_variables=["context", "question"]
143+
)
144+
145+
146+
chain_type_kwargs = {"prompt": PROMPT}
147+
148+
chain = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff", retriever=vectors.as_retriever(), input_key="question" , chain_type_kwargs=chain_type_kwargs)
149+
150+
151+
st.subheader("Most Technically Complex Github Repository is")
152+
153+
query = f"""
154+
155+
156+
Which is the most technically challenging repository from the given CSV file?
157+
158+
Return the name of the repository , the link to the repository and the analysis of the repository showing why it is the most technically challenging/Complex repository.Try to provide a detailed analysis to hold your answer strong
159+
160+
The output should be in the following format:
161+
162+
Repository Name: <name of the repository>
163+
Repository Link: <link to the repository>
164+
Analysis: <analysis of the repository>
165+
166+
Provide a clickable link to the repository as well like this:
167+
To get the repo url , you can use this format :
168+
169+
The username is : "{username}"
170+
171+
172+
"https://github.com/{username}/repository_name"
173+
174+
175+
[Repository Name](Repository Link) --> This is Important.Don't skip it
176+
177+
178+
Let's think step by step about how to answer this question:
179+
180+
"""
181+
result = chain({"question": query})
182+
if result is not None:
183+
st.write(result['result'])
184+
else:
185+
st.info("Please wait..")
186+
st.stop()
187+
188+
189+
190+
191+
# Main app
192+
def main():
193+
config.init()
194+
# Set up the app title and sidebar
195+
st.title("GitHub Automated Analysis Tool")
196+
st.sidebar.title("GitHub Automated Analysis Tool")
197+
198+
# Input field for GitHub username
199+
username = st.sidebar.text_input("Enter GitHub Username")
200+
201+
# Submit and clear buttons
202+
submit_button = st.sidebar.button("Submit")
203+
clear_button = st.sidebar.button("Clear")
204+
st.sidebar.header("About")
205+
st.sidebar.info("This Python-based tool , when given a GitHub user's URL, returns the most technically complex and challenging repository from that user's profile. The tool will use GPT and LangChain to assess each repository individually before determining the most technically challenging one.")
206+
st.divider()
207+
st.sidebar.write("This tool is created by [MANI KUMAR REDDY U](https/github.com/manikumarreddyu).")
208+
209+
# Display the repositories
210+
if submit_button:
211+
st.subheader(f"Repositories for {username}")
212+
repos = fetch_github_repos(username)
213+
if repos:
214+
display_repos(repos)
215+
st.info("Analysis of the repositories using LangChain and ChatGPT started. Please wait...")
216+
get_user_repos(username)
217+
st.error("Invalid username or unable to fetch repositories")
218+
219+
# Clear the input field
220+
if clear_button:
221+
username = ""
222+
st.experimental_rerun()
223+
224+
225+
226+
227+
228+
if __name__ == "__main__":
229+
main()

0 commit comments

Comments
 (0)