Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
def analyze_github_repo(repo_url):
|
| 7 |
# Extract the username and repo name from the GitHub URL
|
| 8 |
if "github.com" not in repo_url:
|
|
@@ -41,46 +57,29 @@ def analyze_github_repo(repo_url):
|
|
| 41 |
'contributions': contributor['contributions']
|
| 42 |
})
|
| 43 |
|
| 44 |
-
#
|
| 45 |
-
|
| 46 |
-
'Stars': stars,
|
| 47 |
-
'Forks': forks,
|
| 48 |
-
'Open Issues': issues,
|
| 49 |
-
'Contributors': len(contributors)
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
# Create the bar plot
|
| 53 |
-
fig, ax = plt.subplots()
|
| 54 |
-
ax.bar(metrics.keys(), metrics.values(), color=['blue', 'green', 'red', 'orange'])
|
| 55 |
-
|
| 56 |
-
ax.set_xlabel('Metrics')
|
| 57 |
-
ax.set_ylabel('Count')
|
| 58 |
-
ax.set_title(f"GitHub Repository Analysis: {repo_url}")
|
| 59 |
|
| 60 |
-
#
|
| 61 |
-
plt.tight_layout()
|
| 62 |
-
plt.savefig("/mnt/data/github_analysis.png")
|
| 63 |
-
plt.close()
|
| 64 |
-
|
| 65 |
-
# Prepare contributor data for display
|
| 66 |
-
contributor_info = "Contributors and Their Commit Contributions:\n"
|
| 67 |
for contributor in contributors:
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
return result
|
| 74 |
|
| 75 |
# Gradio interface for the tool
|
| 76 |
iface = gr.Interface(
|
| 77 |
fn=analyze_github_repo,
|
| 78 |
inputs=gr.Textbox(label="Enter GitHub Repository URL", placeholder="https://github.com/username/repository"),
|
| 79 |
-
outputs=
|
| 80 |
title="GitHub Repository Analysis Tool",
|
| 81 |
-
description="Enter a GitHub repository URL to get
|
| 82 |
)
|
| 83 |
|
| 84 |
# Launch the app
|
| 85 |
iface.launch()
|
| 86 |
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
+
import openai # We will use OpenAI's API to generate the descriptions
|
| 4 |
|
| 5 |
+
# OpenAI API Key (You need to set your API key here)
|
| 6 |
+
openai.api_key = "your-openai-api-key-here"
|
| 7 |
+
|
| 8 |
+
# Function to generate AI-based description for each contributor
|
| 9 |
+
def generate_contributor_description(contributor_name, contributions):
|
| 10 |
+
prompt = f"Generate an in-depth analysis of the contribution of {contributor_name} to a GitHub repository, with {contributions} commits. Focus on the impact, type of contributions, and significance of their work."
|
| 11 |
+
|
| 12 |
+
response = openai.Completion.create(
|
| 13 |
+
engine="text-davinci-003", # Use the appropriate model for text generation
|
| 14 |
+
prompt=prompt,
|
| 15 |
+
max_tokens=150,
|
| 16 |
+
temperature=0.7
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
return response.choices[0].text.strip()
|
| 20 |
+
|
| 21 |
+
# Function to fetch repository details from GitHub and generate descriptions for contributors
|
| 22 |
def analyze_github_repo(repo_url):
|
| 23 |
# Extract the username and repo name from the GitHub URL
|
| 24 |
if "github.com" not in repo_url:
|
|
|
|
| 57 |
'contributions': contributor['contributions']
|
| 58 |
})
|
| 59 |
|
| 60 |
+
# Prepare the text for repository details
|
| 61 |
+
result = f"Repository: {repo_url}\nStars: {stars}\nForks: {forks}\nOpen Issues: {issues}\n\nContributors' Contributions:\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
# Add AI-generated descriptions for each contributor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
for contributor in contributors:
|
| 65 |
+
contributor_name = contributor['login']
|
| 66 |
+
contributions = contributor['contributions']
|
| 67 |
+
description = generate_contributor_description(contributor_name, contributions)
|
| 68 |
+
result += f"{contributor_name} with {contributions} contributions: {description}\n"
|
| 69 |
+
|
| 70 |
+
return result
|
| 71 |
|
| 72 |
# Gradio interface for the tool
|
| 73 |
iface = gr.Interface(
|
| 74 |
fn=analyze_github_repo,
|
| 75 |
inputs=gr.Textbox(label="Enter GitHub Repository URL", placeholder="https://github.com/username/repository"),
|
| 76 |
+
outputs=gr.Textbox(label="Repository Analysis"),
|
| 77 |
title="GitHub Repository Analysis Tool",
|
| 78 |
+
description="Enter a GitHub repository URL to get an in-depth analysis of contributors' contributions using AI, including stars, forks, issues, and a detailed description of each contributor's work."
|
| 79 |
)
|
| 80 |
|
| 81 |
# Launch the app
|
| 82 |
iface.launch()
|
| 83 |
|
| 84 |
+
|
| 85 |
+
|