AliMustapha commited on
Commit
13e5da4
·
1 Parent(s): 163491f

add app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ 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)
9
+ self.setup_ui()
10
+
11
+ def setup_ui(self):
12
+ with gr.Blocks() as demo:
13
+ gr.Label(value="Exploring Global Gender Disparities in Public Code Contributions")
14
+ name = gr.Textbox(label="Name")
15
+ output = gr.Textbox(label="Predicted Gender")
16
+ name_buttom = gr.Button("Predict")
17
+ name_buttom.click(self.predict_name, inputs=name, outputs=output, api_name="greet")
18
+
19
+ name = gr.Textbox(label="Git-url")
20
+ pie_chart_output = gr.Plot()
21
+ data_output =gr.Dataframe()
22
+
23
+ name_buttom = gr.Button("Predict")
24
+ name_buttom.click(self.predict_github_url, inputs=name, outputs=[pie_chart_output, data_output])
25
+
26
+ self.demo = demo
27
+
28
+ def predict_name(self, name):
29
+ prediction, proba = self.gender_predictor.predict_gender(name)
30
+
31
+ if prediction == 0:
32
+ prediction = "Male with probability: " + str(proba) + "%"
33
+ elif prediction == 1:
34
+ prediction = "Female with probability: " + str(proba) + "%"
35
+ else:
36
+ prediction = "Unknown or not a name"
37
+
38
+ prediction = name + " is " + prediction
39
+ return prediction
40
+ def predict_github_url(self, url):
41
+
42
+ commit_info = CommitInfo(url)
43
+
44
+ df,first_commit_dates = commit_info.get_first_commit_dates()
45
+ first_commit_dates[['Predicted_Gender', 'Confidence']] = first_commit_dates['Author'].apply(lambda name: pd.Series(self.gender_predictor.predict_gender(name)))
46
+ first_commit_dates['Predicted_Gender'] = first_commit_dates['Predicted_Gender'].replace({0: "Male", 1: "Female", 2: "Unknown"})
47
+ counts = first_commit_dates['Predicted_Gender'].value_counts()
48
+ colors = ["blue", "pink", "gray"]
49
+ fig = go.Figure(data=[go.Pie(labels=first_commit_dates['Predicted_Gender'].unique(), values=counts, marker=dict(colors=colors))])
50
+
51
+ # Convert the chart to HTML and return it
52
+ return fig,first_commit_dates
53
+ def launch(self):
54
+ self.demo.launch()
55
+
56
+ if __name__ == "__main__":
57
+ modelpath = "saved_model/bestmodel.tf"
58
+ app = GenderPredictorApp(modelpath)
59
+ app.launch()