PraneshJs commited on
Commit
8a87e88
·
verified ·
1 Parent(s): 77d2267

added files to hf

Browse files
azure_ai.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ from openai import AzureOpenAI
4
+
5
+ load_dotenv()
6
+
7
+ client = AzureOpenAI(
8
+ api_version="2024-12-01-preview",
9
+ azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
10
+ api_key=os.getenv("AZURE_OPENAI_KEY")
11
+ )
12
+
13
+ def enhance_with_ai(repo_info):
14
+ file_summaries = "\n".join([
15
+ f"### {name}\n```{content[:300]}```"
16
+ for name, content in list(repo_info['files'].items())[:10]
17
+ ])
18
+
19
+ prompt = f"""
20
+ Create a professional README.md for a GitHub project named "{repo_info['name']}".
21
+
22
+ Description: {repo_info['description']}
23
+ Topics: {', '.join(repo_info['topics'])}
24
+
25
+ The project includes the following files:
26
+ {file_summaries}
27
+
28
+ README must include: Introduction, Features, Installation, Usage, Contributing, and License.
29
+ """
30
+
31
+ response = client.chat.completions.create(
32
+ model=os.getenv("AZURE_DEPLOYMENT_NAME"),
33
+ messages=[
34
+ {"role": "system", "content": "You are a helpful assistant that creates GitHub READMEs. You must follow the provided structure and include all necessary sections. Use necessary emojies and markdown formatting."},
35
+ {"role": "user", "content": prompt}
36
+ ],
37
+ temperature=0.7,
38
+ max_tokens=1000
39
+ )
40
+
41
+ return response.choices[0].message.content
github_analyzer.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from github import Github
2
+ from urllib.parse import urlparse
3
+ import os
4
+ from dotenv import load_dotenv
5
+
6
+ load_dotenv()
7
+
8
+ def extract_repo_name(url):
9
+ path = urlparse(url).path.strip("/")
10
+ return path.split("/")[-2], path.split("/")[-1]
11
+
12
+ def is_important_file(path):
13
+ ignored_dirs = ["node_modules", "test", "__tests__", ".git", "build", ".next", ".vscode"]
14
+ important_dirs = ["src", "components", "pages", "hooks", "controller", "service"]
15
+ important_exts = [".py", ".js", ".ts", ".jsx", ".tsx", ".java"]
16
+
17
+ if any(ignored in path for ignored in ignored_dirs):
18
+ return False
19
+
20
+ if any(dir_ in path for dir_ in important_dirs) and any(path.endswith(ext) for ext in important_exts):
21
+ return True
22
+
23
+ if path.count("/") <= 1 and any(path.endswith(ext) for ext in important_exts):
24
+ return True
25
+
26
+ return False
27
+
28
+ def get_filtered_file_contents(repo, path=""):
29
+ contents = repo.get_contents(path)
30
+ all_files = {}
31
+ for content in contents:
32
+ if content.type == "dir":
33
+ all_files.update(get_filtered_file_contents(repo, content.path))
34
+ else:
35
+ if is_important_file(content.path):
36
+ try:
37
+ file_data = content.decoded_content.decode("utf-8")
38
+ all_files[content.path] = file_data
39
+ except Exception as e:
40
+ all_files[content.path] = f"Unable to read: {e}"
41
+ return all_files
42
+
43
+ def analyze_repo(repo_url):
44
+ g = Github(os.getenv("GITHUB_TOKEN"))
45
+ owner, name = extract_repo_name(repo_url)
46
+ repo = g.get_repo(f"{owner}/{name}")
47
+
48
+ info = {
49
+ "name": repo.name,
50
+ "description": repo.description,
51
+ "topics": repo.get_topics(),
52
+ "files": get_filtered_file_contents(repo),
53
+ "url": repo.html_url
54
+ }
55
+ return info
license_generator.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datetime
2
+ import os
3
+
4
+ def generate_license(license_type, username):
5
+ year = datetime.datetime.now().year
6
+ template_path = f"templates/licenses/{license_type}.txt"
7
+
8
+ if not os.path.exists(template_path):
9
+ return None
10
+
11
+ with open(template_path, "r", encoding="utf-8") as file:
12
+ content = file.read()
13
+
14
+ content = content.replace("[year]", str(year)).replace("[fullname]", username)
15
+
16
+ with open("LICENSE", "w", encoding="utf-8") as file:
17
+ file.write(content)
18
+
19
+ return license_type
readme_generator.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ def generate_readme(repo_info, content, license_type=None):
2
+ with open("README.md", "w", encoding="utf-8") as f:
3
+ f.write(f"# {repo_info['name']}\n\n")
4
+ f.write(content)
5
+ if license_type:
6
+ f.write(f"\n\n## License\nThis project is licensed under the **{license_type}** License.")
7
+ f.write(f"\n\n---\n🔗 GitHub Repo: {repo_info['url']}")
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Flask
2
+ Flask-Cors
3
+ openai
4
+ PyGithub
5
+ python-dotenv
6
+ gunicorn