MarkAdamsMSBA24 commited on
Commit
a5ec74e
·
verified ·
1 Parent(s): d6e3c55

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch
4
+
5
+ # Load the model and tokenizer
6
+ tokenizer = AutoTokenizer.from_pretrained("MarkAdamsMSBA24/ADRv2024")
7
+ model = AutoModelForSequenceClassification.from_pretrained("MarkAdamsMSBA24/ADRv2024")
8
+
9
+ # Define the prediction function
10
+ def get_prediction(text):
11
+ inputs = tokenizer(text, return_tensors="pt", max_length=512, truncation=True, padding=True)
12
+ with torch.no_grad():
13
+ outputs = model(**inputs)
14
+ prediction_scores = outputs.logits
15
+ predicted_class = torch.argmax(prediction_scores, dim=-1).item()
16
+ return f"Predicted Class: {predicted_class}", prediction_scores.tolist()
17
+
18
+ iface = gr.Interface(
19
+ fn=get_prediction,
20
+ inputs=gr.Textbox(lines=4, placeholder="Type your text..."),
21
+ outputs=[gr.Textbox(label="Prediction"), gr.Dataframe(label="Scores")],
22
+ title="BERT Sequence Classification Demo",
23
+ description="This demo uses a BERT model hosted on Hugging Face to classify text sequences."
24
+ )
25
+
26
+ if __name__ == "__main__":
27
+ iface.launch()