commit 2
Browse files
app.py
CHANGED
|
@@ -1,7 +1,88 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
# Constant: Hours per month for 1 FTE
|
| 4 |
+
HOURS_PER_FTE_PER_MONTH = 160
|
| 5 |
|
| 6 |
+
|
| 7 |
+
def calculate_fte(resource_data, months, rate_per_fte):
|
| 8 |
+
"""
|
| 9 |
+
resource_data: string input (name,hours per line)
|
| 10 |
+
months: total project duration
|
| 11 |
+
rate_per_fte: billing per FTE per month
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
if not resource_data.strip():
|
| 15 |
+
return "Please enter resource data.", "", ""
|
| 16 |
+
|
| 17 |
+
total_hours = 0
|
| 18 |
+
details = []
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
lines = resource_data.strip().split("\n")
|
| 22 |
+
|
| 23 |
+
for line in lines:
|
| 24 |
+
name, hours = line.split(",")
|
| 25 |
+
name = name.strip()
|
| 26 |
+
hours = float(hours.strip())
|
| 27 |
+
|
| 28 |
+
total_hours += hours
|
| 29 |
+
details.append(f"{name}: {hours} hrs")
|
| 30 |
+
|
| 31 |
+
except Exception:
|
| 32 |
+
return "Invalid format. Use: Name,Hours per line", "", ""
|
| 33 |
+
|
| 34 |
+
# Calculate FTE
|
| 35 |
+
total_fte = total_hours / (HOURS_PER_FTE_PER_MONTH * months)
|
| 36 |
+
|
| 37 |
+
# Total cost
|
| 38 |
+
total_cost = total_fte * rate_per_fte * months
|
| 39 |
+
|
| 40 |
+
return (
|
| 41 |
+
"\n".join(details),
|
| 42 |
+
round(total_fte, 3),
|
| 43 |
+
f"${round(total_cost, 2)}"
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
# Gradio UI
|
| 48 |
+
with gr.Blocks() as app:
|
| 49 |
+
gr.Markdown("## 📊 FTE Billing Calculator")
|
| 50 |
+
|
| 51 |
+
gr.Markdown(
|
| 52 |
+
"Enter resource data in this format:\n\n"
|
| 53 |
+
"`Name, Hours`\n\nExample:\n"
|
| 54 |
+
"Alice, 120\nBob, 140"
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
resource_input = gr.Textbox(
|
| 58 |
+
label="Resource Data",
|
| 59 |
+
lines=6,
|
| 60 |
+
placeholder="Alice, 120\nBob, 140"
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
months_input = gr.Number(
|
| 64 |
+
label="Project Duration (Months)",
|
| 65 |
+
value=1
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
rate_input = gr.Number(
|
| 69 |
+
label="Rate per FTE per Month ($)",
|
| 70 |
+
value=10000
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
calculate_btn = gr.Button("Calculate")
|
| 74 |
+
|
| 75 |
+
gr.Markdown("### Results")
|
| 76 |
+
|
| 77 |
+
resource_output = gr.Textbox(label="Resource Breakdown")
|
| 78 |
+
fte_output = gr.Textbox(label="Total FTE")
|
| 79 |
+
cost_output = gr.Textbox(label="Total Cost")
|
| 80 |
+
|
| 81 |
+
calculate_btn.click(
|
| 82 |
+
fn=calculate_fte,
|
| 83 |
+
inputs=[resource_input, months_input, rate_input],
|
| 84 |
+
outputs=[resource_output, fte_output, cost_output]
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
if __name__ == "__main__":
|
| 88 |
+
app.launch()
|