Spaces:
Sleeping
Sleeping
espejelomar
commited on
Commit
•
0faf251
1
Parent(s):
5d8523b
Upload folder using huggingface_hub
Browse files- README.md +3 -9
- data/source/all_networks_developer_classification.csv +0 -0
- github_metrics/__init__.py +0 -0
- github_metrics/main.py +107 -0
- poetry.lock +0 -0
- pyproject.toml +19 -0
- requirements.txt +4 -0
- tests/__init__.py +0 -0
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
|
4 |
-
colorFrom: green
|
5 |
-
colorTo: green
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 4.
|
8 |
-
app_file: app.py
|
9 |
-
pinned: false
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: Starknet_Dev_Metrics
|
3 |
+
app_file: github_metrics/main.py
|
|
|
|
|
4 |
sdk: gradio
|
5 |
+
sdk_version: 4.7.1
|
|
|
|
|
6 |
---
|
|
|
|
data/source/all_networks_developer_classification.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
github_metrics/__init__.py
ADDED
File without changes
|
github_metrics/main.py
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
from io import StringIO
|
5 |
+
from termcolor import colored
|
6 |
+
|
7 |
+
# Load the dataset with debug prints
|
8 |
+
def load_dataset():
|
9 |
+
try:
|
10 |
+
print(colored("Loading dataset...", "blue"))
|
11 |
+
df = pd.read_csv("data/source/all_networks_developer_classification.csv")
|
12 |
+
# Ensure the month_year column is in the correct datetime format
|
13 |
+
df['month_year'] = pd.to_datetime(df['month_year'], format='%B_%Y') # Adjust format if necessary
|
14 |
+
return df
|
15 |
+
except Exception as e:
|
16 |
+
print(colored(f"Error loading dataset: {e}", "red"))
|
17 |
+
raise
|
18 |
+
|
19 |
+
# Process input and generate plot and classification with debug prints
|
20 |
+
def process_input(input_text, uploaded_file):
|
21 |
+
try:
|
22 |
+
print(colored("Processing input...", "blue"))
|
23 |
+
|
24 |
+
# Read GitHub handles from input text or uploaded file
|
25 |
+
if uploaded_file is not None:
|
26 |
+
print(colored("Reading from uploaded file...", "blue"))
|
27 |
+
input_text = uploaded_file.read().decode("utf-8")
|
28 |
+
github_handles = [handle.strip() for handle in input_text.split(",")]
|
29 |
+
print(colored(f"GitHub handles: {github_handles}", "blue"))
|
30 |
+
|
31 |
+
# Load dataset
|
32 |
+
df = load_dataset()
|
33 |
+
|
34 |
+
# Filter dataset for the provided GitHub handles
|
35 |
+
print(colored("Filtering dataset...", "blue"))
|
36 |
+
filtered_df = df[df['developer'].isin(github_handles)]
|
37 |
+
|
38 |
+
# Generate plot
|
39 |
+
print(colored("Generating plot...", "blue"))
|
40 |
+
fig, ax = plt.subplots()
|
41 |
+
for handle in github_handles:
|
42 |
+
dev_df = filtered_df[filtered_df['developer'] == handle]
|
43 |
+
dev_df = dev_df.sort_values('month_year')
|
44 |
+
ax.plot(dev_df['month_year'], dev_df['total_commits'], label=handle)
|
45 |
+
|
46 |
+
ax.set_xlabel("Month")
|
47 |
+
ax.set_ylabel("Number of Commits")
|
48 |
+
ax.legend()
|
49 |
+
plt.xticks(rotation=45)
|
50 |
+
plt.tight_layout()
|
51 |
+
|
52 |
+
# Generate classification table
|
53 |
+
print(colored("Classifying developers...", "blue"))
|
54 |
+
classification = []
|
55 |
+
for handle in github_handles:
|
56 |
+
dev_df = filtered_df[filtered_df['developer'] == handle]
|
57 |
+
last_3_months = pd.Timestamp.now() - pd.DateOffset(months=3)
|
58 |
+
recent_activity = dev_df[dev_df['month_year'] >= last_3_months]
|
59 |
+
total_recent_commits = recent_activity['total_commits'].sum()
|
60 |
+
|
61 |
+
if dev_df.empty:
|
62 |
+
status = "Always been inactive"
|
63 |
+
elif recent_activity.empty:
|
64 |
+
status = "Previously active but no longer"
|
65 |
+
elif total_recent_commits < 20:
|
66 |
+
status = "Low-level active"
|
67 |
+
else:
|
68 |
+
status = "Highly involved"
|
69 |
+
|
70 |
+
classification.append((handle, status))
|
71 |
+
|
72 |
+
classification_df = pd.DataFrame(classification, columns=["Developer", "Classification"]).sort_values("Classification", ascending=False)
|
73 |
+
print(colored("Classification completed.", "blue"))
|
74 |
+
|
75 |
+
# Return plot and classification table
|
76 |
+
return fig, classification_df
|
77 |
+
except Exception as e:
|
78 |
+
print(colored(f"Error processing input: {e}", "red"))
|
79 |
+
raise
|
80 |
+
|
81 |
+
# Gradio interface with descriptions and debug prints
|
82 |
+
with gr.Blocks() as app:
|
83 |
+
gr.Markdown("## GitHub Starknet Developer Insights")
|
84 |
+
gr.Markdown("""
|
85 |
+
This tool allows you to analyze the GitHub activity of developers within the Starknet ecosystem.
|
86 |
+
Enter GitHub handles separated by commas or upload a CSV file with GitHub handles in a single column
|
87 |
+
to see their monthly commit activity and their current involvement classification.
|
88 |
+
""")
|
89 |
+
|
90 |
+
with gr.Row():
|
91 |
+
text_input = gr.Textbox(label="Enter GitHub handles separated by commas", placeholder="e.g., user1,user2,user3")
|
92 |
+
file_input = gr.File(label="Or upload a CSV file with GitHub handles in a single column", type="binary")
|
93 |
+
gr.Markdown("""
|
94 |
+
*Note:* When uploading a CSV, ensure it contains a single column of GitHub handles without a header row.
|
95 |
+
""")
|
96 |
+
btn = gr.Button("Analyze")
|
97 |
+
plot_output = gr.Plot(label="Commits per Month")
|
98 |
+
table_output = gr.Dataframe(label="Developer Classification")
|
99 |
+
|
100 |
+
btn.click(process_input, inputs=[text_input, file_input], outputs=[plot_output, table_output])
|
101 |
+
|
102 |
+
print(colored("Gradio app initialized.", "blue"))
|
103 |
+
|
104 |
+
if __name__ == "__main__":
|
105 |
+
print(colored("Launching app...", "blue"))
|
106 |
+
app.launch(share=True)
|
107 |
+
|
poetry.lock
ADDED
The diff for this file is too large to render.
See raw diff
|
|
pyproject.toml
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[tool.poetry]
|
2 |
+
name = "github-metrics"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = ""
|
5 |
+
authors = ["Omar U. Espejel <espejelomar@gmail.com>"]
|
6 |
+
readme = "README.md"
|
7 |
+
packages = [{include = "github_metrics"}]
|
8 |
+
|
9 |
+
[tool.poetry.dependencies]
|
10 |
+
python = "^3.11"
|
11 |
+
gradio = "^4.19.2"
|
12 |
+
pandas = "^2.2.1"
|
13 |
+
matplotlib = "^3.8.3"
|
14 |
+
termcolor = "^2.4.0"
|
15 |
+
|
16 |
+
|
17 |
+
[build-system]
|
18 |
+
requires = ["poetry-core"]
|
19 |
+
build-backend = "poetry.core.masonry.api"
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
gradio
|
3 |
+
matplotlib
|
4 |
+
termcolor
|
tests/__init__.py
ADDED
File without changes
|