Spaces:
Runtime error
Runtime error
Commit ·
a93aad3
1
Parent(s): e50c7a7
code cleaning
Browse files
app.py
CHANGED
|
@@ -7,16 +7,16 @@ from GitScraping import CommitInfo
|
|
| 7 |
from get_region import RegionPredictor
|
| 8 |
import pandas as pd
|
| 9 |
import utils.plot as plot
|
|
|
|
|
|
|
| 10 |
class GenderPredictorApp:
|
| 11 |
def __init__(self, modelpath):
|
| 12 |
self.gender_predictor = GenderPredictor(modelpath)
|
| 13 |
-
self.Region_predictor=RegionPredictor("saved_model/Regions")
|
| 14 |
|
| 15 |
self.setup_ui()
|
| 16 |
|
| 17 |
def setup_ui(self):
|
| 18 |
-
# with gr.Blocks() as demo:
|
| 19 |
-
# gr.Label(value="Exploring Global Gender Disparities in Public Code Contributions")
|
| 20 |
name = gr.inputs.Textbox(label="Name")
|
| 21 |
output = gr.outputs.Textbox(label="Predicted Gender")
|
| 22 |
interface1_fn = gr.Interface(fn=self.predict_name, inputs=name, outputs=output, title="GitGender: Exploring Global Gender Disparities in Public Code Contributions",cache_examples=True )
|
|
@@ -25,7 +25,6 @@ class GenderPredictorApp:
|
|
| 25 |
histo_chart = gr.Plot(label="Known commits by gender")
|
| 26 |
region_commits = gr.Plot(label="Known commits by gender")
|
| 27 |
data_output =gr.Dataframe(headers=None,label="Contributers Details")
|
| 28 |
-
# name_buttom = gr.Button("Predict")
|
| 29 |
interface2_fn = gr.Interface(self.predict_github_url, inputs=name, outputs=[pie_chart_output, histo_chart,region_commits,data_output], title="GitGender: Exploring Global Gender Disparities in Public Code Contributions" )
|
| 30 |
demo = gr.TabbedInterface([interface1_fn, interface2_fn], ["Test Model", "Exploring Diversity in GitHub Repositories"])
|
| 31 |
self.demo = demo
|
|
@@ -34,7 +33,6 @@ class GenderPredictorApp:
|
|
| 34 |
|
| 35 |
def predict_name(self, name):
|
| 36 |
prediction, proba = self.gender_predictor.predict_gender(name)
|
| 37 |
-
|
| 38 |
if prediction == 0:
|
| 39 |
prediction = "Male with probability: " + str(proba) + "%"
|
| 40 |
elif prediction == 1:
|
|
@@ -59,7 +57,7 @@ class GenderPredictorApp:
|
|
| 59 |
commit_per_gender_counts = merged_df.groupby(['Year', 'Predicted_Gender']).size().reset_index(name='Count')
|
| 60 |
commits_per_gender=plot.get_commits_per_gender(commit_per_gender_counts)
|
| 61 |
commits_per_region=plot.get_commits_per_region(merged_df,url)
|
| 62 |
-
|
| 63 |
return Gender_Percentage,commits_per_gender,commits_per_region,Results[["Author","sub-region-prediction","Predicted_Gender","First_Commit_Date"]]
|
| 64 |
def launch(self):
|
| 65 |
self.demo.launch()
|
|
|
|
| 7 |
from get_region import RegionPredictor
|
| 8 |
import pandas as pd
|
| 9 |
import utils.plot as plot
|
| 10 |
+
|
| 11 |
+
|
| 12 |
class GenderPredictorApp:
|
| 13 |
def __init__(self, modelpath):
|
| 14 |
self.gender_predictor = GenderPredictor(modelpath)
|
| 15 |
+
self.Region_predictor=RegionPredictor(models_directory="saved_model/Regions")
|
| 16 |
|
| 17 |
self.setup_ui()
|
| 18 |
|
| 19 |
def setup_ui(self):
|
|
|
|
|
|
|
| 20 |
name = gr.inputs.Textbox(label="Name")
|
| 21 |
output = gr.outputs.Textbox(label="Predicted Gender")
|
| 22 |
interface1_fn = gr.Interface(fn=self.predict_name, inputs=name, outputs=output, title="GitGender: Exploring Global Gender Disparities in Public Code Contributions",cache_examples=True )
|
|
|
|
| 25 |
histo_chart = gr.Plot(label="Known commits by gender")
|
| 26 |
region_commits = gr.Plot(label="Known commits by gender")
|
| 27 |
data_output =gr.Dataframe(headers=None,label="Contributers Details")
|
|
|
|
| 28 |
interface2_fn = gr.Interface(self.predict_github_url, inputs=name, outputs=[pie_chart_output, histo_chart,region_commits,data_output], title="GitGender: Exploring Global Gender Disparities in Public Code Contributions" )
|
| 29 |
demo = gr.TabbedInterface([interface1_fn, interface2_fn], ["Test Model", "Exploring Diversity in GitHub Repositories"])
|
| 30 |
self.demo = demo
|
|
|
|
| 33 |
|
| 34 |
def predict_name(self, name):
|
| 35 |
prediction, proba = self.gender_predictor.predict_gender(name)
|
|
|
|
| 36 |
if prediction == 0:
|
| 37 |
prediction = "Male with probability: " + str(proba) + "%"
|
| 38 |
elif prediction == 1:
|
|
|
|
| 57 |
commit_per_gender_counts = merged_df.groupby(['Year', 'Predicted_Gender']).size().reset_index(name='Count')
|
| 58 |
commits_per_gender=plot.get_commits_per_gender(commit_per_gender_counts)
|
| 59 |
commits_per_region=plot.get_commits_per_region(merged_df,url)
|
| 60 |
+
|
| 61 |
return Gender_Percentage,commits_per_gender,commits_per_region,Results[["Author","sub-region-prediction","Predicted_Gender","First_Commit_Date"]]
|
| 62 |
def launch(self):
|
| 63 |
self.demo.launch()
|