File size: 1,240 Bytes
61b9c03 afd2a42 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification
# Load the model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("padmajabfrl/Gender-Classification")
model = AutoModelForSequenceClassification.from_pretrained("padmajabfrl/Gender-Classification")
# Function to predict gender
def predict_gender(name):
inputs = tokenizer(name, return_tensors="pt")
outputs = model(**inputs)
predictions = outputs.logits.argmax(dim=-1)
predicted_label = model.config.id2label[predictions.item()]
return predicted_label
# Create a Gradio interface
with gr.Blocks() as demo:
gr.Markdown("<h1 style='text-align: center;'>Kaleida Gender Prediction Transformer</h1>")
gr.Markdown("<h3 style='text-align: center;'>Tops Infosolution 🤝 Kaleida</h3>")
with gr.Row():
with gr.Column():
name_input = gr.Textbox(label="Enter a Name", placeholder="Type a name here...", lines=1)
classify_button = gr.Button("Predict Gender")
with gr.Column():
output_label = gr.Label(label="Predicted Gender")
classify_button.click(predict_gender, inputs=name_input, outputs=output_label)
# Launch the app
demo.launch()
|