gradio/demo/gender_sentence_default_interpretation/run.py
aliabid94 ce47c48ebc
Update component config (#1089)
* first commit

* changes

* restore defualt_value name

* changes

* rm value=

* rm value=

* rm value=

* changes

* changes

* changes

* rename default_val to value

* changes

* changes

* changes

* changes

* format

* changes

* changes

* format

* test fix

Co-authored-by: Ali Abid <aliabid94@gmail.com>
2022-05-10 17:11:43 -07:00

24 lines
661 B
Python

import gradio as gr
male_words, female_words = ["he", "his", "him"], ["she", "hers", "her"]
def gender_of_sentence(sentence):
male_count = len([word for word in sentence.split() if word.lower() in male_words])
female_count = len(
[word for word in sentence.split() if word.lower() in female_words]
)
total = max(male_count + female_count, 1)
return {"male": male_count / total, "female": female_count / total}
demo = gr.Interface(
fn=gender_of_sentence,
inputs=gr.Textbox(value="She went to his house to get her keys."),
outputs="label",
interpretation="default",
)
if __name__ == "__main__":
demo.launch()