Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,28 +0,0 @@
|
|
| 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 |
-
|
| 11 |
-
def get_prediction(text):
|
| 12 |
-
X_test = str(text).lower()
|
| 13 |
-
encoded_input = tokenizer(X_test, return_tensors='pt')
|
| 14 |
-
output = model(**encoded_input)
|
| 15 |
-
scores = output[0][0].detach()
|
| 16 |
-
scores = torch.nn.functional.softmax(scores)
|
| 17 |
-
return {"Severe Reaction": float(scores.numpy()[1]), "Non-severe Reaction": float(scores.numpy()[0])}
|
| 18 |
-
|
| 19 |
-
iface = gr.Interface(
|
| 20 |
-
fn=get_prediction,
|
| 21 |
-
inputs=gr.Textbox(lines=4, placeholder="Type your text..."),
|
| 22 |
-
outputs=[gr.Label(label="Prediction"), gr.Dataframe(label="Scores")],
|
| 23 |
-
title="BERT Sequence Classification Demo",
|
| 24 |
-
description="This demo uses a BERT model hosted on Hugging Face to classify text sequences."
|
| 25 |
-
)
|
| 26 |
-
|
| 27 |
-
if __name__ == "__main__":
|
| 28 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|