Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
# Function to fetch repository details from GitHub
|
5 |
+
def analyze_github_repo(repo_url):
|
6 |
+
# Extract the username and repo name from the GitHub URL
|
7 |
+
if "github.com" not in repo_url:
|
8 |
+
return "Please provide a valid GitHub repository URL."
|
9 |
+
|
10 |
+
parts = repo_url.split('/')
|
11 |
+
if len(parts) < 5:
|
12 |
+
return "URL should be in the format: https://github.com/username/repository"
|
13 |
+
|
14 |
+
user, repo = parts[3], parts[4]
|
15 |
+
|
16 |
+
# GitHub API endpoint to get repository details
|
17 |
+
api_url = f"https://api.github.com/repos/{user}/{repo}"
|
18 |
+
response = requests.get(api_url)
|
19 |
+
|
20 |
+
# Check if repository exists
|
21 |
+
if response.status_code == 404:
|
22 |
+
return "Repository not found."
|
23 |
+
|
24 |
+
# Parse the response
|
25 |
+
data = response.json()
|
26 |
+
|
27 |
+
# Extract relevant information
|
28 |
+
stars = data.get('stargazers_count', 'N/A')
|
29 |
+
forks = data.get('forks_count', 'N/A')
|
30 |
+
issues = data.get('open_issues_count', 'N/A')
|
31 |
+
contributors_url = data.get('contributors_url', None)
|
32 |
+
|
33 |
+
# Get number of contributors
|
34 |
+
contributors = "N/A"
|
35 |
+
if contributors_url:
|
36 |
+
contributors_data = requests.get(contributors_url).json()
|
37 |
+
contributors = len(contributors_data)
|
38 |
+
|
39 |
+
# Return the analysis result
|
40 |
+
result = (
|
41 |
+
f"Repository: {repo_url}\n"
|
42 |
+
f"Stars: {stars}\n"
|
43 |
+
f"Forks: {forks}\n"
|
44 |
+
f"Open Issues: {issues}\n"
|
45 |
+
f"Contributors: {contributors}"
|
46 |
+
)
|
47 |
+
|
48 |
+
return result
|
49 |
+
|
50 |
+
# Gradio interface for the tool
|
51 |
+
iface = gr.Interface(
|
52 |
+
fn=analyze_github_repo,
|
53 |
+
inputs=gr.Textbox(label="Enter GitHub Repository URL", placeholder="https://github.com/username/repository"),
|
54 |
+
outputs=gr.Textbox(label="Repository Analysis", placeholder="Analysis will be displayed here..."),
|
55 |
+
title="GitHub Repository Analysis Tool",
|
56 |
+
description="Enter a GitHub repository URL to get basic analytics including stars, forks, issues, and contributors."
|
57 |
+
)
|
58 |
+
|
59 |
+
# Launch the app
|
60 |
+
iface.launch()
|