ai-coaching-app / app.py
lokesh341's picture
Update app.py
04d5fc9 verified
import gradio as gr
from transformers import pipeline
# Load the model
try:
generator = pipeline('text-generation', model='distilgpt2')
except Exception as e:
print(f"Error loading model: {str(e)}")
generator = None
def generate_coaching(supervisor_role, supervisor_name, location, project_id, milestones, reflection_log):
if generator is None:
return "Error: Model not loaded.", "Error: Model not loaded.", False
try:
# Default values for missing inputs
supervisor_role = supervisor_role or "Supervisor"
supervisor_name = supervisor_name or "Unknown"
location = location or "Unknown Location"
project_id = project_id or "Unknown Project"
milestones = milestones or ""
reflection_log = reflection_log or ""
# Generate checklist
checklist_prompt = f"Generate a daily checklist for a {supervisor_role} named {supervisor_name} at {location} working on project {project_id} with milestones: {milestones}."
checklist_result = generator(checklist_prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
# Generate tips
tips_prompt = f"Provide coaching tips for a {supervisor_role} based on reflection: {reflection_log}."
tips_result = generator(tips_prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
# Simulate KPI alert
alert = len(milestones) < 10 # Simplified logic
return checklist_result, tips_result, alert
except Exception as e:
return f"Error: {str(e)}", f"Error: {str(e)}", False
# Create Gradio interface
interface = gr.Interface(
fn=generate_coaching,
inputs=[
gr.Textbox(label="Supervisor Role", placeholder="e.g., Site Manager"),
gr.Textbox(label="Supervisor Name", placeholder="e.g., John Doe"),
gr.Textbox(label="Location", placeholder="e.g., Site A"),
gr.Textbox(label="Project ID", placeholder="e.g., project123"),
gr.Textbox(label="Milestones", placeholder="e.g., Foundation complete"),
gr.Textbox(label="Reflection Log", placeholder="e.g., Team performed well today.")
],
outputs=[
gr.Textbox(label="Checklist"),
gr.Textbox(label="Tips"),
gr.Checkbox(label="KPI Alert")
],
title="AI Coaching App",
description="Generate daily checklists and tips for supervisors using AI.",
allow_flagging="never"
)
# Launch the interface
interface.launch(server_name="0.0.0.0", server_port=7860)