Spaces:
Runtime error
Runtime error
Commit ·
f919758
1
Parent(s): d812bab
add commit counts per years
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@ from get_gender import GenderPredictor
|
|
| 3 |
from GitScraping import CommitInfo
|
| 4 |
import pandas as pd
|
| 5 |
import plotly.graph_objects as go
|
|
|
|
|
|
|
| 6 |
class GenderPredictorApp:
|
| 7 |
def __init__(self, modelpath):
|
| 8 |
self.gender_predictor = GenderPredictor(modelpath)
|
|
@@ -16,9 +18,10 @@ class GenderPredictorApp:
|
|
| 16 |
interface1_fn = gr.Interface(fn=self.predict_name, inputs=name, outputs=output, title="GitGender: Exploring Global Gender Disparities in Public Code Contributions")
|
| 17 |
name = gr.inputs.Textbox(label="Git-url")
|
| 18 |
pie_chart_output = gr.Plot()
|
| 19 |
-
|
|
|
|
| 20 |
# name_buttom = gr.Button("Predict")
|
| 21 |
-
interface2_fn = gr.Interface(self.predict_github_url, inputs=name, outputs=[pie_chart_output, data_output], title="GitGender: Exploring Global Gender Disparities in Public Code Contributions")
|
| 22 |
demo = gr.TabbedInterface([interface1_fn, interface2_fn], ["Test Model", "Exploring Diversity in GitHub Repositories"])
|
| 23 |
self.demo = demo
|
| 24 |
|
|
@@ -46,10 +49,34 @@ class GenderPredictorApp:
|
|
| 46 |
counts = first_commit_dates['Predicted_Gender'].value_counts()
|
| 47 |
# print(counts)
|
| 48 |
colors = ["blue", "pink", "gray"]
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# Convert the chart to HTML and return it
|
| 52 |
-
return
|
| 53 |
def launch(self):
|
| 54 |
self.demo.launch()
|
| 55 |
|
|
|
|
| 3 |
from GitScraping import CommitInfo
|
| 4 |
import pandas as pd
|
| 5 |
import plotly.graph_objects as go
|
| 6 |
+
from plotly.subplots import make_subplots
|
| 7 |
+
|
| 8 |
class GenderPredictorApp:
|
| 9 |
def __init__(self, modelpath):
|
| 10 |
self.gender_predictor = GenderPredictor(modelpath)
|
|
|
|
| 18 |
interface1_fn = gr.Interface(fn=self.predict_name, inputs=name, outputs=output, title="GitGender: Exploring Global Gender Disparities in Public Code Contributions")
|
| 19 |
name = gr.inputs.Textbox(label="Git-url")
|
| 20 |
pie_chart_output = gr.Plot()
|
| 21 |
+
histo_chart = gr.Plot()
|
| 22 |
+
data_output =gr.Dataframe(headers=None)
|
| 23 |
# name_buttom = gr.Button("Predict")
|
| 24 |
+
interface2_fn = gr.Interface(self.predict_github_url, inputs=name, outputs=[pie_chart_output, data_output,histo_chart], title="GitGender: Exploring Global Gender Disparities in Public Code Contributions")
|
| 25 |
demo = gr.TabbedInterface([interface1_fn, interface2_fn], ["Test Model", "Exploring Diversity in GitHub Repositories"])
|
| 26 |
self.demo = demo
|
| 27 |
|
|
|
|
| 49 |
counts = first_commit_dates['Predicted_Gender'].value_counts()
|
| 50 |
# print(counts)
|
| 51 |
colors = ["blue", "pink", "gray"]
|
| 52 |
+
Gender_Percentage = go.Figure(data=[go.Pie(labels=first_commit_dates['Predicted_Gender'].unique(), values=counts, marker=dict(colors=colors))])
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
# ******************************
|
| 56 |
+
merged_df = df.merge(first_commit_dates[["Author","Predicted_Gender","Confidence"]], on=["Author"])
|
| 57 |
+
# Group by Year and Predicted_Gender, then count the occurrences
|
| 58 |
+
gender_counts = merged_df.groupby(['Year', 'Predicted_Gender']).size().reset_index(name='Count')
|
| 59 |
|
| 60 |
+
male_count=gender_counts[gender_counts["Predicted_Gender"]=="Male"]
|
| 61 |
+
female_count=gender_counts[gender_counts["Predicted_Gender"]=="Female"]
|
| 62 |
+
fig = make_subplots(rows=1, cols=1, shared_xaxes=True)
|
| 63 |
+
fig.add_trace(
|
| 64 |
+
go.Bar(x=male_count['Year'], y=male_count['Count'], name='Male'),
|
| 65 |
+
row=1, col=1
|
| 66 |
+
)
|
| 67 |
+
fig.add_trace(
|
| 68 |
+
go.Bar(x=female_count['Year'], y=female_count['Count'], name='Female'),
|
| 69 |
+
row=1, col=1
|
| 70 |
+
)
|
| 71 |
+
fig.update_layout(
|
| 72 |
+
height=400,
|
| 73 |
+
xaxis=dict(title="gender commits per year"),
|
| 74 |
+
yaxis1=dict(title='Male'),
|
| 75 |
+
yaxis2=dict(title='Female'),
|
| 76 |
+
hovermode='x unified'
|
| 77 |
+
)
|
| 78 |
# Convert the chart to HTML and return it
|
| 79 |
+
return Gender_Percentage,first_commit_dates[["Author","Author_Timezone","Predicted_Gender"]],fig
|
| 80 |
def launch(self):
|
| 81 |
self.demo.launch()
|
| 82 |
|