| import os |
| import gradio as gr |
| import openai |
|
|
| |
| os.environ['MPLCONFIGDIR'] = '/tmp/matplotlib' |
|
|
| |
| openai.api_key = os.environ.get("OPENAI_API_KEY", "your-api-key") |
|
|
| def generate_prompt(manager, peer, self_review): |
| return f""" |
| Act as an expert HR coach analyzing 360° feedback. Generate a structured development report with these sections: |
| 1. Key Strengths (3-5 bullet points) 💪 |
| 2. Growth Areas (3-5 actionable items) 📈 |
| 3. Development Plan (2-3 concrete suggestions) 🚀 |
| |
| Feedback Sources: |
| Manager: {manager or 'No input'} |
| Peer: {peer or 'No input'} |
| Self: {self_review or 'No input'} |
| |
| Guidelines: |
| - Use empathetic, professional tone |
| - Connect insights across feedback sources |
| - Focus on measurable improvements |
| - Include both technical and soft skills |
| - Highlight 1 'quick win' priority |
| - Avoid generic advice - be specific |
| - Format in markdown with emojis |
| - Keep output under 300 words |
| """ |
|
|
| def generate_feedback(manager, peer, self_review): |
| """Generate AI feedback summary from all inputs""" |
| try: |
| prompt = generate_prompt(manager, peer, self_review) |
| |
| response = openai.ChatCompletion.create( |
| model="gpt-3.5-turbo", |
| messages=[{"role": "user", "content": prompt}], |
| temperature=0.7, |
| max_tokens=500 |
| ) |
| |
| return response.choices[0].message.content |
| except Exception as e: |
| return f"⚠️ Error generating feedback: {str(e)}" |
|
|
| with gr.Blocks(theme=gr.themes.Soft(), title="360° Feedback AI Coach") as app: |
| gr.Markdown("# 🚀 360° Feedback AI Coach") |
| gr.Markdown("Get personalized development insights from manager, peer, and self feedback") |
| |
| with gr.Row(): |
| with gr.Column(): |
| manager_input = gr.Textbox(label="Manager Feedback", lines=5, placeholder="Manager's comments...") |
| peer_input = gr.Textbox(label="Peer Feedback", lines=5, placeholder="Peer's comments...") |
| self_input = gr.Textbox(label="Self Review", lines=5, placeholder="Your self-assessment...") |
| |
| with gr.Column(): |
| output = gr.Markdown(label="AI Feedback Summary") |
| with gr.Row(): |
| submit_btn = gr.Button("Generate Report", variant="primary") |
| clear_btn = gr.Button("Clear") |
| |
| gr.Examples( |
| examples=[ |
| ["Strong technical skills but needs improvement in communication", "Always helpful with technical problems", "I need to work on presentation skills"], |
| ["Excellent leadership, should delegate more", "Great team player", "Want to improve time management"], |
| ], |
| inputs=[manager_input, peer_input, self_input], |
| label="Example Inputs" |
| ) |
| |
| submit_btn.click( |
| fn=generate_feedback, |
| inputs=[manager_input, peer_input, self_input], |
| outputs=output |
| ) |
| |
| clear_btn.click(lambda: [None, None, None, None], None, [manager_input, peer_input, self_input, output]) |
|
|
| if __name__ == "__main__": |
| app.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860))) |