Spaces:
Running
Running
| import streamlit as st | |
| import pandas as pd | |
| from pathlib import Path | |
| import numpy as np | |
| from openai import OpenAI | |
| from sentence_transformers import SentenceTransformer | |
| from sklearn.preprocessing import MinMaxScaler | |
| from io import StringIO | |
| def load_model(): | |
| """Loads the SentenceTransformer model and caches it.""" | |
| model = SentenceTransformer("all-MiniLM-L6-v2") | |
| return model | |
| # Load the model by calling the cached function | |
| model = load_model() | |
| # model = SentenceTransformer("all-MiniLM-L6-v2") | |
| minmax = MinMaxScaler() | |
| pillar_weights_csv = '''Pillar,Normalized Weight | |
| Student-centric,0.28 | |
| Digitally advanced,0.22 | |
| Fostering technologies to stay afloat,0.15 | |
| Scaling functionalities to create new value,0.20 | |
| Justifying value to design change,0.15 | |
| ''' | |
| def main(): | |
| # st.write('# Semantic Alignment App') | |
| tab_bp, tab_is, tab_matching = st.tabs(['Business Processes', 'Information Systems', 'BP-IS Matching'], default='BP-IS Matching') | |
| with tab_bp: | |
| # st.write('## Business Processes') | |
| bp_df = pd.read_csv('labelled_data/business_processes_quoted.csv') | |
| st.dataframe(bp_df) | |
| st.write(bp_df.shape) | |
| with tab_is: | |
| # st.write('## Information Systems') | |
| is_df = pd.read_csv('labelled_data/information_systems.csv') | |
| st.dataframe(is_df) | |
| st.markdown('''# New dataframe''') | |
| st.markdown(f'''{is_df.shape}''') | |
| with tab_matching: | |
| business_process_classes = bp_df['business_process_class'].unique() | |
| information_system_classes = is_df['information_system_class'].unique() | |
| # st.write(business_process_classes) | |
| # st.write(information_system_classes) | |
| embeddings_bp_classes = model.encode(business_process_classes) | |
| embeddings_is_classes = model.encode(information_system_classes) | |
| # st.write(embeddings_bp_classes.shape, embeddings_is_classes.shape) | |
| similarities = model.similarity(embeddings_bp_classes, embeddings_is_classes) | |
| similarities_minmax = minmax.fit_transform(similarities) | |
| # st.write('similarities.max()', similarities_minmax.max()) # bp, is | |
| # st.write('similarities.min()', similarities_minmax.min()) # bp, is | |
| # matrix = np.random.randn(len(business_process_classes), len(information_system_classes)) | |
| # matrix = minmax.fit_transform(matrix) * 100 | |
| matrix_df = pd.DataFrame(similarities_minmax, columns=information_system_classes , index=business_process_classes) | |
| st.write('### Alignment Matrix') | |
| st.dataframe(matrix_df) | |
| # st.write('### Bigger than 70') | |
| # matrix_df[matrix_df>70] | |
| st.write('### Max Score for each BP') | |
| max_col = similarities_minmax.max(1) | |
| max_col_arg = similarities_minmax.argmax(1) | |
| # information_system_classes[max_col], business_process_classes | |
| s = pd.DataFrame({'information_system_classes':information_system_classes[max_col_arg], 'business_process_classes':business_process_classes, 'score':max_col }) | |
| st.dataframe(s) | |
| st.write('### Pillars') | |
| pillar_weights = pd.read_csv(StringIO(pillar_weights_csv)) | |
| # step 1 | |
| st.write("### Step 1 (from ChatGPT)") | |
| st.dataframe(pillar_weights) | |
| unique_pillars = pillar_weights['Pillar'] | |
| is_bp_pairs = s.apply(lambda x: x['information_system_classes'] + ' ' + x['business_process_classes'], axis=1) | |
| embeddings_unique_pillars = model.encode(unique_pillars) | |
| embeddings_is_bp_pairs = model.encode(is_bp_pairs) | |
| similarities_pillars = model.similarity(embeddings_unique_pillars, embeddings_is_bp_pairs) | |
| similarities_pillars_minmax = minmax.fit_transform(similarities_pillars) | |
| similarities_pillars_minmax*=5 | |
| # st.write(similarities_pillars_minmax) | |
| similarities_pillars_df = pd.DataFrame(similarities_pillars_minmax) | |
| similarities_pillars_df.index = unique_pillars | |
| similarities_pillars_df.columns = is_bp_pairs | |
| # step 2 | |
| st.write("### Step 2 - BP-IS pair and Pillars (Embedding Model)") | |
| st.write(similarities_pillars_df.T) | |
| # step 3 | |
| st.write("### Step 3 - Normalized Strategic Score (*0<score<1*)") | |
| strategic_scores = {k:0 for k in similarities_pillars_df.columns} | |
| for i, row in similarities_pillars_df.T.iterrows(): | |
| for p, s in zip(row.index, row.values): | |
| # st.write(row.name) | |
| # st.write(p) | |
| # st.write(s) | |
| w = pillar_weights[pillar_weights['Pillar'] == p]['Normalized Weight'].values[0] | |
| # st.write(w) | |
| weighted = w*s | |
| # st.write('weighted', row.name, weighted) | |
| strategic_scores[row.name] += weighted | |
| # st.write('---') | |
| # break | |
| strategic_scores_normalized = [[k,v/5] for k,v in strategic_scores.items()] | |
| # st.write('strategic_scores_normalized', strategic_scores_normalized) | |
| strategic_scores_normalized_df = pd.DataFrame(strategic_scores_normalized, columns=['BP IS pair', 'Strategic Scores Normalized'], ) | |
| st.write(strategic_scores_normalized_df) | |
| if __name__=='__main__': | |
| main() | |
| s = ''' | |
| You are a strategic evaluation analyst with expertise in digital transformation and multi-criteria decision analysis. Your task is to assign importance weights to strategic pillars and assess how each BP-IS class supports these pillars. | |
| Context: | |
| You are given five strategic pillars that define an institution’s digital transformation strategy, along with a set of BP-IS (Business Process - Information System) classes. Each BP-IS class represents a cluster of business processes and supporting information systems. The five strategic pillars (with their focus areas) are: | |
| 1. Student-centric: Enhancing student outcomes, services, and experience. | |
| 2. Digitally advanced: Strength and maturity of digital infrastructure and systems. | |
| 3. Fostering technologies to stay afloat: Supporting operational continuity and resilience. | |
| 4. Scaling functionalities to create new value: Enabling innovation, growth, and new services. | |
| 5. Justifying value to design change: Demonstrating measurable value that drives institutional change and improvement. | |
| Your goal is to perform a strategic alignment evaluation using these pillars. You will: | |
| 1. Weight the Pillars: Assign a normalized weight (between 0 and 1) to each of the five pillars, reflecting their overall importance to the institution’s digital transformation. The weights must sum up to 1.0. Use your expert judgment to prioritize which pillars are most critical in the given context. | |
| 2. Score BP–IS Class Contributions: For each BP-IS class provided: | |
| a. Evaluate its contribution to each pillar on a scale from 0 to 5 (where 0 = no contribution, 5 = maximum contribution). Base these scores on the class’s described functions, impact, and (if provided) its semantic alignment score from a prior phase. Consider how well the class supports the intent of each pillar’s definition. | |
| b. Provide a brief rationale (one line) explaining the class’s overall strategic role or impact. This should clarify why it scored as it did and how it supports the institution’s strategy. | |
| 3. Calculate Strategic Score: Compute the final Strategic Alignment Score for each class as a weighted sum of its pillar scores. Use the formula: | |
| This results in a composite score on a 0-5 scale for the class’s overall strategic alignment. | |
| ''' | |