ashutoshtitoria's picture
Update app.py
afd2a42 verified
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()