import gradio as gr # Constant: Hours per month for 1 FTE HOURS_PER_FTE_PER_MONTH = 160 def calculate_fte(resource_data, months, rate_per_fte): """ resource_data: string input (name,hours per line) months: total project duration rate_per_fte: billing per FTE per month """ if not resource_data.strip(): return "Please enter resource data.", "", "" total_hours = 0 details = [] try: lines = resource_data.strip().split("\n") for line in lines: name, hours = line.split(",") name = name.strip() hours = float(hours.strip()) total_hours += hours details.append(f"{name}: {hours} hrs") except Exception: return "Invalid format. Use: Name,Hours per line", "", "" # Calculate FTE total_fte = total_hours / (HOURS_PER_FTE_PER_MONTH * months) # Total cost total_cost = total_fte * rate_per_fte * months return ( "\n".join(details), round(total_fte, 3), f"${round(total_cost, 2)}" ) # Gradio UI with gr.Blocks() as app: gr.Markdown("## 📊 FTE Billing Calculator") gr.Markdown( "Enter resource data in this format:\n\n" "`Name, Hours`\n\nExample:\n" "Alice, 120\nBob, 140" ) resource_input = gr.Textbox( label="Resource Data", lines=6, placeholder="Alice, 120\nBob, 140" ) months_input = gr.Number( label="Project Duration (Months)", value=1 ) rate_input = gr.Number( label="Rate per FTE per Month ($)", value=10000 ) calculate_btn = gr.Button("Calculate") gr.Markdown("### Results") resource_output = gr.Textbox(label="Resource Breakdown") fte_output = gr.Textbox(label="Total FTE") cost_output = gr.Textbox(label="Total Cost") calculate_btn.click( fn=calculate_fte, inputs=[resource_input, months_input, rate_input], outputs=[resource_output, fte_output, cost_output] ) if __name__ == "__main__": app.launch()