Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,49 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
|
|
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
@st.cache_resource
|
| 5 |
def load_model():
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
st.title("Check-In Classifier")
|
| 11 |
-
st.write("Classify your check-in as Good, Average, Bad, Repetitive, or Great.")
|
| 12 |
|
| 13 |
-
|
|
|
|
| 14 |
|
|
|
|
| 15 |
if st.button("Classify"):
|
| 16 |
-
if
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
else:
|
| 22 |
-
st.warning("Please enter a check-in.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 4 |
|
| 5 |
+
# Streamlit app layout
|
| 6 |
+
st.set_page_config(page_title="Check-In Classifier", page_icon="📝")
|
| 7 |
+
st.title("📝 Check-In Classifier Chatbot")
|
| 8 |
+
st.write("Classify your check-in and get feedback!")
|
| 9 |
+
|
| 10 |
+
# Load your model and tokenizer from Hugging Face
|
| 11 |
@st.cache_resource
|
| 12 |
def load_model():
|
| 13 |
+
model_name = "SleepyTerr/checkin-classifier"
|
| 14 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 15 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 16 |
+
return tokenizer, model
|
| 17 |
+
|
| 18 |
+
tokenizer, model = load_model()
|
| 19 |
|
| 20 |
+
# Label map
|
| 21 |
+
label_map = {0: "Good", 1: "Average", 2: "Bad", 3: "Repetitive", 4: "Great"}
|
| 22 |
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
# User input
|
| 25 |
+
checkin = st.text_area("Enter your check-in:")
|
| 26 |
|
| 27 |
+
# Prediction and feedback
|
| 28 |
if st.button("Classify"):
|
| 29 |
+
if checkin.strip():
|
| 30 |
+
inputs = tokenizer(checkin, return_tensors="pt", truncation=True, padding=True)
|
| 31 |
+
with torch.no_grad():
|
| 32 |
+
logits = model(**inputs).logits
|
| 33 |
+
prediction = torch.argmax(logits, dim=-1).item()
|
| 34 |
+
rating = label_map[prediction]
|
| 35 |
+
|
| 36 |
+
st.success(f"Your check-in was rated as: **{rating}**")
|
| 37 |
+
|
| 38 |
+
# Feedback messages
|
| 39 |
+
feedback = {
|
| 40 |
+
"Good": "That's a good check-in!",
|
| 41 |
+
"Average": "That's an average check-in, still room for improvement though.",
|
| 42 |
+
"Bad": "Ehh... Not enough detail. It seems thrown together and like you didn't do anything. Do better.",
|
| 43 |
+
"Repetitive": "Not good or bad, just explain better and stop repeating the same thing to make it longer..",
|
| 44 |
+
"Great": "I have no feedback, your check-in is amazing!"
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
st.info(feedback[rating])
|
| 48 |
else:
|
| 49 |
+
st.warning("Please enter a check-in to classify.")
|