mkoot007 commited on
Commit
aa289c2
1 Parent(s): ee47fbb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
4
+ model = AutoModelForSequenceClassification.from_pretrained("bert-base-uncased", num_labels=2)
5
+
6
+ def classify_text(text):
7
+ encoded_text = tokenizer(text, truncation=True, padding='max_length', max_length=512, return_tensors='pt')
8
+ predictions = model(**encoded_text)
9
+ predicted_label = predictions.logits.argmax(-1).item()
10
+ predicted_class = model.config.id2label[predicted_label]
11
+
12
+ return predicted_class
13
+ interface = gr.Interface(
14
+ fn=classify_text,
15
+ inputs=[gr.Textbox(label="Input Text")],
16
+ outputs=[gr.Textbox(label="Predicted Class")],
17
+ title="Text Classification App"
18
+ )
19
+ interface.launch(share=True)