gbakidz commited on
Commit
571e676
1 Parent(s): a046679

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+
4
+ # Load model and tokenizer
5
+ model_name = "castorini/afriberta_large"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
+
9
+ # Define prediction function
10
+ def predict(text):
11
+ inputs = tokenizer(text, return_tensors="pt")
12
+ outputs = model(**inputs)
13
+ return outputs.logits.argmax(-1).item()
14
+
15
+ # Gradio Interface
16
+ iface = gr.Interface(fn=predict, inputs="text", outputs="label", title="AfriBERTa Demo")
17
+ iface.launch()