Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
import openai # We will use OpenAI's API to generate the descriptions | |
# OpenAI API Key (You need to set your API key here) | |
openai.api_key = "your-openai-api-key-here" | |
# Function to generate AI-based description for each contributor | |
def generate_contributor_description(contributor_name, contributions): | |
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." | |
response = openai.Completion.create( | |
engine="text-davinci-003", # Use the appropriate model for text generation | |
prompt=prompt, | |
max_tokens=150, | |
temperature=0.7 | |
) | |
return response.choices[0].text.strip() | |
# Function to fetch repository details from GitHub and generate descriptions for contributors | |
def analyze_github_repo(repo_url): | |
# Extract the username and repo name from the GitHub URL | |
if "github.com" not in repo_url: | |
return "Please provide a valid GitHub repository URL." | |
parts = repo_url.split('/') | |
if len(parts) < 5: | |
return "URL should be in the format: https://github.com/username/repository" | |
user, repo = parts[3], parts[4] | |
# GitHub API endpoint to get repository details | |
api_url = f"https://api.github.com/repos/{user}/{repo}" | |
response = requests.get(api_url) | |
# Check if repository exists | |
if response.status_code == 404: | |
return "Repository not found." | |
# Parse the response | |
data = response.json() | |
# Extract relevant information | |
stars = data.get('stargazers_count', 'N/A') | |
forks = data.get('forks_count', 'N/A') | |
issues = data.get('open_issues_count', 'N/A') | |
contributors_url = data.get('contributors_url', None) | |
# Get number of contributors and their contributions (commit count) | |
contributors = [] | |
if contributors_url: | |
contributors_data = requests.get(contributors_url).json() | |
for contributor in contributors_data: | |
contributors.append({ | |
'login': contributor['login'], | |
'contributions': contributor['contributions'] | |
}) | |
# Prepare the text for repository details | |
result = f"Repository: {repo_url}\nStars: {stars}\nForks: {forks}\nOpen Issues: {issues}\n\nContributors' Contributions:\n" | |
# Add AI-generated descriptions for each contributor | |
for contributor in contributors: | |
contributor_name = contributor['login'] | |
contributions = contributor['contributions'] | |
description = generate_contributor_description(contributor_name, contributions) | |
result += f"{contributor_name} with {contributions} contributions: {description}\n" | |
return result | |
# Gradio interface for the tool | |
iface = gr.Interface( | |
fn=analyze_github_repo, | |
inputs=gr.Textbox(label="Enter GitHub Repository URL", placeholder="https://github.com/username/repository"), | |
outputs=gr.Textbox(label="Repository Analysis"), | |
title="GitHub Repository Analysis Tool", | |
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." | |
) | |
# Launch the app | |
iface.launch() | |