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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import plotly.express as px
|
| 4 |
+
from fpdf import FPDF
|
| 5 |
+
import base64
|
| 6 |
+
from transformers import pipeline
|
| 7 |
+
from openai import OpenAI
|
| 8 |
+
|
| 9 |
+
pipe = pipeline("sentiment-analysis",
|
| 10 |
+
model="finiteautomata/bertweet-base-sentiment-analysis")
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def col_labels(df, column_name):
|
| 14 |
+
label_count = df[column_name].value_counts()
|
| 15 |
+
return label_count
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def plots(labels):
|
| 19 |
+
fig = px.pie(names=labels.index, values=labels.values)
|
| 20 |
+
fig.update_layout(
|
| 21 |
+
showlegend=True,
|
| 22 |
+
autosize=False,
|
| 23 |
+
width=500,
|
| 24 |
+
height=500
|
| 25 |
+
)
|
| 26 |
+
st.plotly_chart(fig, use_container_width=True)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def generate_pdf_report(df, questions):
|
| 30 |
+
pdf = FPDF()
|
| 31 |
+
pdf.add_page()
|
| 32 |
+
pdf.set_font("Arial", size=12, style='B')
|
| 33 |
+
pdf.cell(200, 10, txt="Bennett University NAAC Survey Report",
|
| 34 |
+
ln=True, align="C")
|
| 35 |
+
pdf.ln(10)
|
| 36 |
+
for question in questions:
|
| 37 |
+
pdf.multi_cell(200, 10, txt=question)
|
| 38 |
+
labels = col_labels(df, question)
|
| 39 |
+
for label, count in labels.items():
|
| 40 |
+
pdf.cell(200, 10, txt=f"{label}: {count}", ln=True)
|
| 41 |
+
pdf.ln(5)
|
| 42 |
+
pdf_file = "survey_report.pdf"
|
| 43 |
+
pdf.output(pdf_file)
|
| 44 |
+
return pdf_file
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def chunking(arr):
|
| 48 |
+
max_chunk_size = 1024
|
| 49 |
+
chunks = []
|
| 50 |
+
current_chunk = ""
|
| 51 |
+
|
| 52 |
+
for recommendation in arr:
|
| 53 |
+
if len(current_chunk) + len(arr) + len('. ') <= max_chunk_size:
|
| 54 |
+
current_chunk += recommendation + '. '
|
| 55 |
+
else:
|
| 56 |
+
chunks.append(current_chunk[:-2])
|
| 57 |
+
current_chunk = recommendation + '. '
|
| 58 |
+
|
| 59 |
+
if current_chunk:
|
| 60 |
+
chunks.append(current_chunk[:-2])
|
| 61 |
+
|
| 62 |
+
return chunks
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def generate_summary(text):
|
| 66 |
+
input_chunks = chunking(text)
|
| 67 |
+
output_chunks = []
|
| 68 |
+
client = OpenAI()
|
| 69 |
+
for chunk in input_chunks:
|
| 70 |
+
response = client.completions.create(
|
| 71 |
+
model="gpt-3.5-turbo-instruct",
|
| 72 |
+
prompt=(
|
| 73 |
+
f"Please give summary of:\n{chunk}. The summary given should be in bullet points.\n\nSummary:"),
|
| 74 |
+
temperature=0.7,
|
| 75 |
+
max_tokens=1024,
|
| 76 |
+
n=1,
|
| 77 |
+
stop=None
|
| 78 |
+
)
|
| 79 |
+
summary = response.choices[0].text.strip()
|
| 80 |
+
output_chunks.append(summary)
|
| 81 |
+
return " ".join(output_chunks)
|
| 82 |
+
|
| 83 |
+
st.set_page_config(
|
| 84 |
+
page_title="Bennett University NAAC Survey Report",
|
| 85 |
+
page_icon="📊",
|
| 86 |
+
layout="wide"
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
hide_streamlit_style = """
|
| 90 |
+
<style>
|
| 91 |
+
#MainMenu {visibility: hidden;}
|
| 92 |
+
footer {visibility: hidden;}
|
| 93 |
+
</style>
|
| 94 |
+
"""
|
| 95 |
+
|
| 96 |
+
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
st.markdown(
|
| 100 |
+
"<h1 style='text-align: center; color: #008080;'>Bennett University NAAC Survey Report</h1>",
|
| 101 |
+
unsafe_allow_html=True
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
file = st.file_uploader("Upload Response File", type=['csv'])
|
| 105 |
+
|
| 106 |
+
if file is not None:
|
| 107 |
+
st.sidebar.info("File uploaded successfully! Proceed with the analysis.")
|
| 108 |
+
|
| 109 |
+
df = pd.read_csv(file)
|
| 110 |
+
|
| 111 |
+
questions = [
|
| 112 |
+
'How much of the syllabus was covered in the class?',
|
| 113 |
+
'How well did the teachers prepare for the classes?',
|
| 114 |
+
'How well were the teachers able to communicate?',
|
| 115 |
+
'The teacher\'s approach to teaching can best be described as',
|
| 116 |
+
'Fairness of the internal evaluation process by the teachers.',
|
| 117 |
+
'Was your performance in assignments discussed with you?',
|
| 118 |
+
'The institute takes active interest in promoting internship, student exchange, field visit opportunities for students.',
|
| 119 |
+
'The teaching and mentoring process in your institution facilitates you in cognitive, social and emotional growth.',
|
| 120 |
+
'The institution provides multiple opportunities to learn and grow.',
|
| 121 |
+
'Teachers inform you about your expected competencies, course outcomes and programme outcomes.',
|
| 122 |
+
'Your mentor does a necessary follow-up with an assigned task to you.',
|
| 123 |
+
'The teachers illustrate the concepts through examples and applications.',
|
| 124 |
+
'The teachers identify your strengths and encourage you with providing right level of challenges.',
|
| 125 |
+
'Teachers are able to identify your weaknesses and help you to overcome them.',
|
| 126 |
+
'The institution makes effort to engage students in the monitoring, review and continuous quality improvement of the teaching learning process.',
|
| 127 |
+
'The institute/ teachers use student centric methods, such as experiential learning, participative learning and problem solving methodologies for enhancing learning experiences.',
|
| 128 |
+
'Teachers encourage you to participate in extracurricular activities.',
|
| 129 |
+
'Efforts are made by the institute/ teachers to inculcate soft skills, life skills and employability skills to make you ready for the world of work.',
|
| 130 |
+
'What percentage of teachers use ICT tools such as LCD projector, Multimedia, etc. while teaching.',
|
| 131 |
+
'The overall quality of teaching-learning process in your institute is very good.',
|
| 132 |
+
]
|
| 133 |
+
|
| 134 |
+
st.write("---")
|
| 135 |
+
st.write("### Survey Questions Analysis")
|
| 136 |
+
st.write("Below are the analysis results for each survey question:")
|
| 137 |
+
|
| 138 |
+
pos_comments = []
|
| 139 |
+
neg_comments = []
|
| 140 |
+
neu_comments = []
|
| 141 |
+
for data in df['Give three observation / suggestions to improve the overall teaching - learning experience in your institution.']:
|
| 142 |
+
sentiment = pipe(data)[0]['label']
|
| 143 |
+
if sentiment == "POS":
|
| 144 |
+
pos_comments.append(data)
|
| 145 |
+
if sentiment == "NEG":
|
| 146 |
+
neg_comments.append(data)
|
| 147 |
+
if sentiment == "NEU":
|
| 148 |
+
neu_comments.append(data)
|
| 149 |
+
else:
|
| 150 |
+
neu_comments.append(data)
|
| 151 |
+
|
| 152 |
+
st.subheader("Positive Comments")
|
| 153 |
+
st.write(generate_summary(pos_comments))
|
| 154 |
+
st.write("---")
|
| 155 |
+
st.subheader("Negative Comments")
|
| 156 |
+
st.write(generate_summary(neg_comments))
|
| 157 |
+
|
| 158 |
+
st.sidebar.markdown("---")
|
| 159 |
+
st.sidebar.write("#### Analysis Settings")
|
| 160 |
+
selected_questions = [
|
| 161 |
+
question for question in questions if st.sidebar.checkbox(question, value=True)]
|
| 162 |
+
for question in selected_questions:
|
| 163 |
+
st.write("")
|
| 164 |
+
st.subheader(question)
|
| 165 |
+
labels = col_labels(df, question)
|
| 166 |
+
plots(labels)
|
| 167 |
+
|
| 168 |
+
st.sidebar.markdown("---")
|
| 169 |
+
st.sidebar.write("#### Download Report")
|
| 170 |
+
if st.sidebar.button("Generate PDF Report"):
|
| 171 |
+
pdf_file = generate_pdf_report(df, selected_questions)
|
| 172 |
+
with open(pdf_file, "rb") as f:
|
| 173 |
+
base64_pdf = base64.b64encode(f.read()).decode("utf-8")
|
| 174 |
+
href = f"<a href='data:application/octet-stream;base64,{base64_pdf}' download='survey_report.pdf'><button>Download PDF Report</button></a>"
|
| 175 |
+
st.sidebar.markdown(href, unsafe_allow_html=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
openai
|
| 2 |
+
transformers
|
| 3 |
+
plotly
|
| 4 |
+
fpdf
|
| 5 |
+
emoji
|
| 6 |
+
pandas
|
| 7 |
+
streamlit
|
| 8 |
+
torch
|