mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-15 02:11:15 +08:00
16 lines
634 B
Python
16 lines
634 B
Python
import gradio as gr
|
|
import re
|
|
|
|
male_words, female_words = ["he", "his", "him"], ["she", "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}
|
|
|
|
iface = gr.Interface(
|
|
fn=gender_of_sentence, inputs=gr.inputs.Textbox(default="She went to his house to get her keys."),
|
|
outputs="label", interpretation="default")
|
|
if __name__ == "__main__":
|
|
iface.launch()
|