Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +31 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
from transformers import (AutoTokenizer, AutoModelForSequenceClassification)
|
5 |
+
|
6 |
+
model = AutoModelForSequenceClassification.from_pretrained('tiedaar/metacognitive-cls',
|
7 |
+
num_labels=8,
|
8 |
+
problem_type = "multi_label_classification")
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained('tiedaar/metacognitive-cls', use_fast=False)
|
10 |
+
|
11 |
+
labels = list(model.config.id2label.values())
|
12 |
+
|
13 |
+
def sigmoid(x):
|
14 |
+
return 1/(1 + np.exp(-x))
|
15 |
+
|
16 |
+
def generate_output(sequence):
|
17 |
+
input_ids = tokenizer(sequence, return_tensors='pt')['input_ids']
|
18 |
+
outputs = np.array(model(input_ids).logits.detach().reshape(-1))
|
19 |
+
predictions = sigmoid(outputs)
|
20 |
+
predictions = (predictions > 0.5).astype(int)
|
21 |
+
return predictions
|
22 |
+
|
23 |
+
st.title("Metacognitive Strategy Classification")
|
24 |
+
st.subheader("This app classifies natural language descriptions of study strategies according to the metacognitive strategies being employed")
|
25 |
+
|
26 |
+
sequence = st.text_area("Please input the text here")
|
27 |
+
df = pd.DataFrame(columns=labels)
|
28 |
+
if st.button("Click here"):
|
29 |
+
resp = generate_output(sequence)
|
30 |
+
df.loc[len(df)] = resp
|
31 |
+
st.table(df)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
transformers
|
3 |
+
pandas
|
4 |
+
numpy
|