Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| def time_value_of_money_calculator(capital_expenditure, annual_revenue, operating_expenditure, project_years, minimum_attractive_rate_of_return): | |
| capital_expenditure = float(capital_expenditure) | |
| annual_revenue = float(annual_revenue) | |
| operating_expenditure = float(operating_expenditure) | |
| project_years = int(project_years) | |
| minimum_attractive_rate_of_return = float(minimum_attractive_rate_of_return)/100 | |
| cash_flows = [-capital_expenditure] + [annual_revenue - operating_expenditure] * project_years | |
| net_present_value = sum(cf/(1+minimum_attractive_rate_of_return)**i for i,cf in enumerate(cash_flows)) | |
| cumulative_cash_flow = 0 | |
| payback_period = 0 | |
| for i in range(1, len(cash_flows)): | |
| cumulative_cash_flow += cash_flows[i] | |
| payback_period = i | |
| if cumulative_cash_flow >= capital_expenditure: break | |
| profitability_index = abs(net_present_value/capital_expenditure)*100 | |
| project_status = "β PROJECT VIABLE" if net_present_value>0 else "β PROJECT REVIEW NEEDED" | |
| return f"""<div style=' | |
| animation: slideInUp 0.8s ease-out, glow 2s ease-in-out infinite alternate; | |
| padding: 25px; | |
| background: linear-gradient(145deg, #f8f9ff, #e8ecff); | |
| border-radius: 20px; | |
| border-left: 6px solid #667eea; | |
| box-shadow: 0 15px 35px rgba(102,126,234,0.3); | |
| '> | |
| <h2 style=' | |
| background: linear-gradient(45deg, #1e3c72, #2a5298, #667eea); | |
| -webkit-background-clip: text; | |
| -webkit-text-fill-color: transparent; | |
| margin: 0 0 20px 0; | |
| font-weight: 700; | |
| '>π§ͺ Time Value of Money Analysis</h2> | |
| <div style='font-size: 16px; line-height: 1.8;'> | |
| <h3 style='color: #1e3c72; margin: 15px 0 10px 0;'>π INPUT PARAMETERS</h3> | |
| <table style='width: 100%; border-collapse: collapse; margin-bottom: 20px;'> | |
| <tr style='background: rgba(102,126,234,0.1);'><td><b>CAPEX:</b></td><td>${capital_expenditure:,.0f}</td></tr> | |
| <tr><td><b>REV:</b></td><td>${annual_revenue:,.0f}</td></tr> | |
| <tr style='background: rgba(102,126,234,0.1);'><td><b>OPEX:</b></td><td>${operating_expenditure:,.0f}</td></tr> | |
| </table> | |
| <h3 style='color: #1e3c72; margin: 20px 0 15px 0;'>π― KEY RESULTS</h3> | |
| <div style=' | |
| display: grid; | |
| grid-template-columns: 1fr 1fr; | |
| gap: 15px; | |
| margin-bottom: 20px; | |
| '> | |
| <div style='text-align: center; padding: 15px; background: linear-gradient(135deg, #d4f1ff, #a3d8f4); border-radius: 12px;'> | |
| <div style='font-size: 28px; font-weight: bold; color: #0066cc;'>${net_present_value:,.0f}</div> | |
| <div style='color: #0066cc; font-weight: 600;'>NPV</div> | |
| </div> | |
| <div style='text-align: center; padding: 15px; background: linear-gradient(135deg, #fff3cd, #ffeaa7); border-radius: 12px;'> | |
| <div style='font-size: 28px; font-weight: bold; color: #856404;'>{payback_period} yrs</div> | |
| <div style='color: #856404; font-weight: 600;'>PAYBACK</div> | |
| </div> | |
| </div> | |
| <div style=' | |
| padding: 20px; | |
| background: linear-gradient(135deg, {'#d4edda' if net_present_value>0 else '#f8d7da'}, {'#c3e6cb' if net_present_value>0 else '#f5c6cb'}); | |
| border-radius: 15px; | |
| border-left: 6px solid {'#28a745' if net_present_value>0 else '#dc3545'}; | |
| text-align: center; | |
| font-size: 18px; | |
| font-weight: 700; | |
| color: {'#155724' if net_present_value>0 else '#721c24'}; | |
| '>{project_status}</div> | |
| <div style='margin-top: 25px; padding-top: 20px; border-top: 2px solid #e1e5e9; text-align: center; color: #6c757d; font-size: 14px;'> | |
| π¨βπΌ **App Builder: M.Kamran Liaqat** | π **2k23-chE-05** | |
| </div> | |
| </div> | |
| <style> | |
| @keyframes slideInUp {{ | |
| 0% {{ opacity: 0; transform: translateY(50px); }} | |
| 100% {{ opacity: 1; transform: translateY(0); }} | |
| }} | |
| @keyframes glow {{ | |
| 0% {{ box-shadow: 0 15px 35px rgba(102,126,234,0.3); }} | |
| 100% {{ box-shadow: 0 20px 45px rgba(102,126,234,0.5); }} | |
| }} | |
| </style>""" | |
| css = """ | |
| .gradio-container { | |
| background: linear-gradient(135deg, #1e3c72 0%, #2a5298 50%, #0f3460 100%) !important; | |
| min-height: 100vh; | |
| } | |
| .block.gradio-container > div { | |
| background: rgba(255,255,255,0.95) !important; | |
| border-radius: 25px !important; | |
| box-shadow: 0 25px 50px rgba(0,0,0,0.15) !important; | |
| border: 1px solid rgba(255,255,255,0.3) !important; | |
| } | |
| .gr-button { | |
| background: linear-gradient(45deg, #667eea 0%, #764ba2 100%) !important; | |
| border: none !important; | |
| color: white !important; | |
| border-radius: 15px !important; | |
| font-weight: 700 !important; | |
| font-size: 16px !important; | |
| box-shadow: 0 10px 25px rgba(102,126,234,0.4) !important; | |
| transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) !important; | |
| } | |
| .gr-button:hover { | |
| transform: translateY(-3px) scale(1.02) !important; | |
| box-shadow: 0 15px 35px rgba(102,126,234,0.6) !important; | |
| } | |
| .gr-number input, .gr-slider input { | |
| background: rgba(255,255,255,0.95) !important; | |
| border: 2px solid #e8ecff !important; | |
| border-radius: 12px !important; | |
| padding: 15px !important; | |
| font-size: 16px !important; | |
| transition: all 0.3s ease !important; | |
| } | |
| .gr-number input:focus, .gr-slider input:focus { | |
| border-color: #667eea !important; | |
| box-shadow: 0 0 0 3px rgba(102,126,234,0.1) !important; | |
| } | |
| """ | |
| with gr.Blocks(css=css, title="ChemEng TVM Calculator") as demo: | |
| gr.Markdown("# π§ͺ Chemical Engineering TVM Calculator") | |
| gr.Markdown("**Professional Capital Budgeting & Economic Analysis Tool**") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| gr.Markdown("### π° **Financial Inputs**") | |
| capital_expenditure_input = gr.Number(value=10000000, label="**CAPEX** ($)", precision=0) | |
| annual_revenue_input = gr.Number(value=5000000, label="**Annual Revenue** ($)", precision=0) | |
| operating_expenditure_input = gr.Number(value=3500000, label="**OPEX** ($)", precision=0) | |
| with gr.Column(scale=1): | |
| gr.Markdown("### π **Project Parameters**") | |
| project_years_input = gr.Slider(minimum=5, maximum=30, value=15, step=1, label="**Project Years**") | |
| marr_input = gr.Slider(minimum=8, maximum=25, value=12, step=0.5, label="**MARR (%)**") | |
| calculate_button = gr.Button("π¬ **PERFORM ECONOMIC ANALYSIS**", variant="primary", size="lg") | |
| results_output = gr.Markdown() | |
| calculate_button.click(time_value_of_money_calculator, | |
| inputs=[capital_expenditure_input, annual_revenue_input, operating_expenditure_input, project_years_input, marr_input], | |
| outputs=results_output) | |
| demo.launch() |