Spaces:
Runtime error
Runtime error
Sarah Flanagan
commited on
Commit
·
082e680
1
Parent(s):
800e5de
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
from PIL import Image
|
4 |
+
import pandas as pd
|
5 |
+
import matplotlib.pyplot as plt
|
6 |
+
|
7 |
+
labels = ['AS-yes', 'AS-no', 'AS-no_information']
|
8 |
+
|
9 |
+
# Change `transformersbook` to your Hub username
|
10 |
+
model_id = "sarahflan/distilbert-base-uncased-finetuned-AS_sentences"
|
11 |
+
classifier = pipeline("text-classification", model=model_id)
|
12 |
+
|
13 |
+
st.title("Aortic Stenosis sentence classifier ")
|
14 |
+
|
15 |
+
sentence = st.text_input('Echocardiogram demonstrated a heavily calcified aortic valve with limited leaflet mobility. Findings are consistent with severe aortic stenosis.','Patient has AS')
|
16 |
+
|
17 |
+
preds = classifier(sentence, return_all_scores=True)
|
18 |
+
|
19 |
+
preds_df = pd.DataFrame(preds[0], columns=['score'])
|
20 |
+
preds_df['labels'] = labels
|
21 |
+
|
22 |
+
sorted_preds_df = preds_df.sort_values(by='score', ascending=False).head(20)
|
23 |
+
|
24 |
+
fig, ax = plt.subplots()
|
25 |
+
ax.bar(sorted_preds_df['labels'], 100 * sorted_preds_df['score'], color='C0')
|
26 |
+
ax.set_title(f'"{sentence}"')
|
27 |
+
ax.set_ylabel("Class probability (%)")
|
28 |
+
ax.tick_params(axis='x', labelrotation=90)
|
29 |
+
|
30 |
+
st.pyplot(fig)
|