File size: 2,078 Bytes
deea5aa 739b64a deea5aa 739b64a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | 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() |