Vineedhar commited on
Commit
ce17064
·
verified ·
1 Parent(s): dc745c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -0
app.py CHANGED
@@ -98,8 +98,80 @@ if uploaded_file is not None:
98
 
99
  df_combined['Self_score'] = df_combined.apply(calculate_self_score, axis=1)
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  st.write("### Output:")
102
  st.write("#### 1. Extracted data: Dimensions Assessment of the leader by: Boss, Colleagues, Colleagues (other b.), Direct reports, Customers and All Raters")
103
  st.write("#### 2. Derived data: Self score")
104
  st.write("### Dataset Table")
105
  st.dataframe(df_combined)
 
 
98
 
99
  df_combined['Self_score'] = df_combined.apply(calculate_self_score, axis=1)
100
 
101
+ #Step 7 : Picking strengths and weaknesses
102
+ # List of keywords/phrases to capture
103
+ keywords = [
104
+ 'Integrity/ Reliability', 'Appearance', 'Enthusiasm/Passion',
105
+ 'Learning Motivation/ Self-Development', 'Ability to Adapt/Flexibility',
106
+ 'Communication/Information', 'Cooperation/ Team spirit',
107
+ 'Handling of Complex Situations', 'Coolness/Handling of Unclear Situations', 'Self-reliance/Initiative',
108
+ 'Conflict Management', 'Ability to Assert Oneself/ Negotiation Skills',
109
+ 'Tact and Sensitivity', 'Quality Orientation', 'Client Orientation',
110
+ 'Specialized Knowledge', 'Methodology/ Didactics/ Language',
111
+ 'Creativity/ Conceptional Skills', 'Project Management',
112
+ 'Result Orientation', 'Leadership Skills', 'Coach and Advisor'
113
+ ]
114
+
115
+ # Extract phrases between "Topics I would like to discuss... " and "Schedule for the follow-up meeting"
116
+ phrases_pattern = r"Please use the form at the end of the section to finalize your development planning\.\s*(.*?)\s*Schedule for the follow-up meeting"
117
+ phrases_matches = re.findall(phrases_pattern, pdf_text, re.DOTALL)
118
+
119
+ # Extract the word after "The biggest strengths and room for improvements perceived by:"
120
+ label_pattern = r"The biggest strengths and room for improvements perceived by:\s*(\w+)"
121
+ labels = re.findall(label_pattern, pdf_text)
122
+
123
+ # Process each match and extract only the required keywords
124
+ json_output = []
125
+ for i, phrases_text in enumerate(phrases_matches):
126
+ extracted_phrases = [
127
+ phrase for phrase in keywords if phrase in phrases_text
128
+ ]
129
+ if extracted_phrases:
130
+ label = labels[i] if i < len(labels) else f"Phrases_{i+1}"
131
+ json_output.append({label: extracted_phrases})
132
+
133
+ # Convert to JSON format
134
+ json_output_str = json.dumps(json_output, indent=2)
135
+
136
+ # Print the JSON result
137
+ #print(json_output_str)
138
+
139
+ json_data = df.to_json(orient='records')
140
+
141
+ data = []
142
+ for item in json_output:
143
+ for label, phrases in item.items():
144
+ for phrase in phrases:
145
+ data.append({'Label': label, 'Dimensions': phrase})
146
+
147
+ df4 = pd.DataFrame(data)
148
+
149
+ #Step 9: Converting Streangths and Weaknesses with scores into json
150
+
151
+ # Filter dataframes based on 'Label' value
152
+ boss, direct, colleague, other_colleague = [df4[df4['Label'] == label].copy() for label in ['Boss', 'Direct', 'Colleagues', 'Colleague (o']]
153
+
154
+ # Create mapping dictionaries from df3
155
+ mappings = {
156
+ 'Boss_score': df_combined.set_index('Dimensions')['Boss_score'].to_dict(),
157
+ 'Report_score': df_combined.set_index('Dimensions')['Report_score'].to_dict(),
158
+ 'Colleague_score': df_combined.set_index('Dimensions')['Colleague_score'].to_dict(),
159
+ 'Other_colleague_score': df_combined.set_index('Dimensions')['Colleague_other_score'].to_dict()
160
+ }
161
+
162
+ # Map the values from df3 to the appropriate DataFrames
163
+ boss['Boss_score'] = boss['Dimensions'].map(mappings['Boss_score'])
164
+ direct['Report_score'] = direct['Dimensions'].map(mappings['Report_score'])
165
+ colleague['Colleague_score'] = colleague['Dimensions'].map(mappings['Colleague_score'])
166
+ other_colleague['Other_colleague_score'] = other_colleague['Dimensions'].map(mappings['Other_colleague_score'])
167
+
168
+ boss.sort_values(by = 'Boss_score', ascending = False)
169
+ boss_json = boss.iloc[3:,1:].to_dict(orient='records')
170
+ prompt = f"You are a corporate trainer who guides me how to behave in corporate settings. You will analyze the top 3 strengths and scores{boss_json} rated by my boss out of 6. You will generate a nudge for each dimension to improveupon these strengths."
171
+
172
  st.write("### Output:")
173
  st.write("#### 1. Extracted data: Dimensions Assessment of the leader by: Boss, Colleagues, Colleagues (other b.), Direct reports, Customers and All Raters")
174
  st.write("#### 2. Derived data: Self score")
175
  st.write("### Dataset Table")
176
  st.dataframe(df_combined)
177
+ st.write(f"#### {print(prompt)}")