ashutoshtitoria commited on
Commit
61b9c03
·
verified ·
1 Parent(s): 51968cd

Create app.py

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