Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
|
6 |
+
classifier = pipeline("zero-shot-classification", model="MoritzLaurer/deberta-v3-large-zeroshot-v2.0")
|
7 |
+
|
8 |
+
def predict_teacher_course(feedback):
|
9 |
+
sequence_to_classify = feedback
|
10 |
+
candidate_labels = ["teacher", "course"]
|
11 |
+
output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
|
12 |
+
return str(output['labels'][0])
|
13 |
+
|
14 |
+
def predict_sentiment(feedback):
|
15 |
+
sequence_to_classify = feedback
|
16 |
+
candidate_labels = ["positive", "negative", "neutral"]
|
17 |
+
output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
|
18 |
+
return str(output['labels'][0])
|
19 |
+
|
20 |
+
def predict_teacher_aspect(feedback):
|
21 |
+
sequence_to_classify = feedback
|
22 |
+
candidate_labels = ['general', 'teaching skills', 'behaviour', 'knowledge', 'experience', 'assessment']
|
23 |
+
output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
|
24 |
+
return str(output['labels'][0])
|
25 |
+
|
26 |
+
def predict_course_aspect(feedback):
|
27 |
+
sequence_to_classify = feedback
|
28 |
+
candidate_labels = ['relevancy', 'general', 'content', 'learning material', 'pace']
|
29 |
+
output = classifier(sequence_to_classify, candidate_labels, multi_label=False)
|
30 |
+
return str(output['labels'][0])
|
31 |
+
|
32 |
+
# Streamlit app layout
|
33 |
+
st.set_page_config(page_title="Aspect-based Sentiment Anlaysis of Student Feedback", layout="centered", initial_sidebar_state="auto")
|
34 |
+
|
35 |
+
st.markdown("""
|
36 |
+
#### This application analyzes the student feedback to determine whether it is about a teacher or a course, detects sentiment, and identifies important teacher or course aspects.
|
37 |
+
""")
|
38 |
+
|
39 |
+
# Get user input
|
40 |
+
user_input = st.text_area("Enter the feedback or comments for analysis:", height=200)
|
41 |
+
|
42 |
+
if st.button("Analyze Text"):
|
43 |
+
if user_input.strip():
|
44 |
+
# Predict whether it's about teacher or course
|
45 |
+
type_result = predict_teacher_course(user_input)
|
46 |
+
sentiment_result = predict_sentiment(user_input)
|
47 |
+
if type_result == 'teacher':
|
48 |
+
aspect_result = predict_teacher_aspect(user_input)
|
49 |
+
else:
|
50 |
+
aspect_result = predict_course_aspect(user_input)
|
51 |
+
|
52 |
+
# Display the results in a nice way
|
53 |
+
st.subheader("Analysis Results")
|
54 |
+
|
55 |
+
st.markdown(f"**Type:** `{type_result}`")
|
56 |
+
|
57 |
+
st.markdown(f"**Sentiment:** `{sentiment_result}`")
|
58 |
+
|
59 |
+
st.write(f"**Aspect:** `{aspect_result}`")
|
60 |
+
else:
|
61 |
+
st.error("Please enter some text for analysis.")
|
62 |
+
|
63 |
+
# Add a footer
|
64 |
+
st.markdown("---")
|
65 |
+
st.markdown("**Developed by Sarang Shaikh**")
|
66 |
+
st.markdown("""
|
67 |
+
Feel free to reach out for more information or suggestions!
|
68 |
+
""")
|