NarayanaRaju/Multi-Domain_Problem-solving
0
1import gradio as gr2 3# =========================================================4# TELANGANA SOR DATABASE5# =========================================================6 7sor_database = {8 9 "rmc m20": {10 "unit": "Cum",11 "material_rate": 4200,12 "labour_rate": 850,13 "machinery_rate": 450,14 "overheads": 300,15 },16 17 "rmc m25": {18 "unit": "Cum",19 "material_rate": 4500,20 "labour_rate": 900,21 "machinery_rate": 500,22 "overheads": 350,23 },24 25 "rmc m30": {26 "unit": "Cum",27 "material_rate": 4900,28 "labour_rate": 950,29 "machinery_rate": 550,30 "overheads": 400,31 },32 33 "steel reinforcement": {34 "unit": "Kg",35 "material_rate": 62,36 "labour_rate": 8,37 "machinery_rate": 3,38 "overheads": 4,39 },40 41 "excavation": {42 "unit": "Cum",43 "material_rate": 0,44 "labour_rate": 180,45 "machinery_rate": 140,46 "overheads": 30,47 }48}49 50 51# =========================================================52# CONSTRUCTION TENDER ANALYZER53# =========================================================54 55def analyze_sor_rate(item_name, quantity):56 57 item = item_name.lower().strip()58 59 if item not in sor_database:60 61 return f"""62ITEM NOT FOUND63 64Available Items:65- RMC M2066- RMC M2567- RMC M3068- Steel Reinforcement69- Excavation70"""71 72 data = sor_database[item]73 74 material = data["material_rate"]75 labour = data["labour_rate"]76 machinery = data["machinery_rate"]77 overheads = data["overheads"]78 79 unit = data["unit"]80 81 basic_rate = material + labour + machinery + overheads82 83 total_amount = basic_rate * quantity84 85 contractor_profit = total_amount * 0.1086 87 gst = (total_amount + contractor_profit) * 0.1888 89 final_amount = total_amount + contractor_profit + gst90 91 return f"""92🏗️ TELANGANA SOR RATE ANALYSIS93==================================================94 95Item:96{item.upper()}97 98Quantity:99{quantity} {unit}100 101--------------------------------------------------102RATE BREAKUP103--------------------------------------------------104 105Material Cost : ₹ {material:,.2f}106Labour Cost : ₹ {labour:,.2f}107Machinery Charges : ₹ {machinery:,.2f}108Overheads : ₹ {overheads:,.2f}109 110--------------------------------------------------111BASIC RATE112--------------------------------------------------113 114Basic Rate : ₹ {basic_rate:,.2f} / {unit}115 116--------------------------------------------------117TOTAL COST ANALYSIS118--------------------------------------------------119 120Basic Amount : ₹ {total_amount:,.2f}121 122Contractor Profit : ₹ {contractor_profit:,.2f}123 124GST @18% : ₹ {gst:,.2f}125 126--------------------------------------------------127FINAL TENDER VALUE128--------------------------------------------------129 130Final Amount : ₹ {final_amount:,.2f}131 132==================================================133RECOMMENDATION134==================================================135 136Recommended Quoted Rate:137₹ {round(final_amount / quantity, 2):,.2f} per {unit}138"""139 140 141# =========================================================142# PROJECT PLANNING ASSISTANT143# =========================================================144 145def project_planner(project_cost, duration):146 147 manpower = int(duration * 6)148 149 monthly_expense = project_cost / duration150 151 return f"""152📅 PROJECT PLANNING ANALYSIS153==================================================154 155Project Duration : {duration} Months156 157Estimated Project Cost : ₹ {project_cost:,.2f}158 159Estimated Manpower : {manpower} Workers160 161Monthly Cash Flow : ₹ {monthly_expense:,.2f}162 163==================================================164SUGGESTED EXECUTION PLAN165==================================================166 1671. Mobilization Phase1682. Procurement Phase1693. Execution Phase1704. QA/QC Inspection1715. Testing & Commissioning1726. Handover173 174==================================================175RISK FACTORS176==================================================177 178• Material price escalation179• Labour shortage180• Delay in approvals181• Weather impact182• Cash flow management183"""184 185 186# =========================================================187# FINANCIAL ANALYZER188# =========================================================189 190def financial_calculator(principal, rate, years):191 192 amount = principal * ((1 + rate / 100) ** years)193 194 interest = amount - principal195 196 monthly_return = amount / (years * 12)197 198 return f"""199💰 FINANCIAL ANALYSIS200==================================================201 202Investment Amount : ₹ {principal:,.2f}203 204Interest Rate : {rate} %205 206Investment Period : {years} Years207 208==================================================209RESULTS210==================================================211 212Final Amount : ₹ {amount:,.2f}213 214Interest Earned : ₹ {interest:,.2f}215 216Monthly Avg Return : ₹ {monthly_return:,.2f}217"""218 219 220# =========================================================221# MATERIAL REQUIREMENT CALCULATOR222# =========================================================223 224def material_calculator(concrete_qty):225 226 cement_bags = concrete_qty * 8227 228 sand = concrete_qty * 0.45229 230 aggregate = concrete_qty * 0.9231 232 return f"""233🧱 MATERIAL REQUIREMENT ANALYSIS234==================================================235 236Concrete Quantity : {concrete_qty} Cum237 238==================================================239ESTIMATED MATERIALS240==================================================241 242Cement Bags : {cement_bags:.0f} Bags243 244Sand Quantity : {sand:.2f} Cum245 246Aggregate Qty : {aggregate:.2f} Cum247 248==================================================249RECOMMENDATION250==================================================251 252• Add 5% wastage margin253• Verify mix design before execution254• Confirm source availability255"""256 257 258# =========================================================259# PIPELINE PRESSURE ANALYZER260# =========================================================261 262def pipeline_analyzer(diameter, pressure):263 264 safe_pressure = diameter * 2.5265 266 if pressure <= safe_pressure:267 status = "SAFE"268 else:269 status = "NOT SAFE"270 271 return f"""272🚰 PIPELINE PRESSURE ANALYSIS273==================================================274 275Pipe Diameter : {diameter} mm276 277Operating Pressure : {pressure} Bar278 279Allowable Pressure : {safe_pressure:.2f} Bar280 281==================================================282STATUS283==================================================284 285Pipeline Condition : {status}286 287==================================================288RECOMMENDATIONS289==================================================290 291• Verify surge pressure292• Check pipe thickness293• Confirm pressure class294• Conduct hydro testing295"""296 297 298# =========================================================299# INVENTORY MANAGEMENT300# =========================================================301 302def inventory_helper(stock, consumption):303 304 days_left = stock / consumption305 306 if days_left < 10:307 status = "URGENT REORDER REQUIRED"308 elif days_left < 30:309 status = "REORDER SOON"310 else:311 status = "STOCK SUFFICIENT"312 313 return f"""314📦 INVENTORY MANAGEMENT REPORT315==================================================316 317Current Stock : {stock}318 319Daily Consumption : {consumption}320 321Estimated Days Left : {days_left:.1f} Days322 323==================================================324STATUS325==================================================326 327{status}328 329==================================================330RECOMMENDATION331==================================================332 333Maintain minimum buffer stock for uninterrupted work.334"""335 336 337# =========================================================338# LABOUR COST ESTIMATOR339# =========================================================340 341def labour_estimator(workers, daily_wage, days):342 343 total_cost = workers * daily_wage * days344 345 return f"""346👷 LABOUR COST ANALYSIS347==================================================348 349Number of Workers : {workers}350 351Daily Wage : ₹ {daily_wage:,.2f}352 353Working Days : {days}354 355==================================================356TOTAL LABOUR COST357==================================================358 359Total Cost : ₹ {total_cost:,.2f}360 361==================================================362RECOMMENDATIONS363==================================================364 365• Include overtime allowance366• Include accommodation cost367• Include safety equipment cost368"""369 370 371# =========================================================372# MAIN UI373# =========================================================374 375with gr.Blocks(title="AI Multi-Domain Problem Solver") as app:376 377 gr.Markdown("""378# 🚀 AI Multi-Domain Problem Solving Application379 380Professional Engineering, Construction,381Financial & Project Management Toolkit382""")383 384 # =====================================================385 # TAB 1 - TENDER ANALYZER386 # =====================================================387 388 with gr.Tab("🏗️ Tender Analyzer"):389 390 item_input = gr.Textbox(391 label="Construction Item",392 placeholder="Example: RMC M30"393 )394 395 quantity_input = gr.Number(396 label="Quantity",397 value=1398 )399 400 analyze_btn = gr.Button("Analyze Rate")401 402 tender_output = gr.Textbox(lines=30)403 404 analyze_btn.click(405 analyze_sor_rate,406 inputs=[item_input, quantity_input],407 outputs=tender_output408 )409 410 # =====================================================411 # TAB 2 - PROJECT PLANNER412 # =====================================================413 414 with gr.Tab("📅 Project Planner"):415 416 project_cost = gr.Number(417 label="Project Cost"418 )419 420 duration = gr.Number(421 label="Duration (Months)"422 )423 424 planner_btn = gr.Button("Generate Plan")425 426 planner_output = gr.Textbox(lines=25)427 428 planner_btn.click(429 project_planner,430 inputs=[project_cost, duration],431 outputs=planner_output432 )433 434 # =====================================================435 # TAB 3 - FINANCIAL ANALYZER436 # =====================================================437 438 with gr.Tab("💰 Financial Analyzer"):439 440 principal = gr.Number(441 label="Investment Amount"442 )443 444 rate = gr.Number(445 label="Interest Rate (%)"446 )447 448 years = gr.Number(449 label="Years"450 )451 452 finance_btn = gr.Button("Calculate")453 454 finance_output = gr.Textbox(lines=20)455 456 finance_btn.click(457 financial_calculator,458 inputs=[principal, rate, years],459 outputs=finance_output460 )461 462 # =====================================================463 # TAB 4 - MATERIAL CALCULATOR464 # =====================================================465 466 with gr.Tab("🧱 Material Calculator"):467 468 concrete_qty = gr.Number(469 label="Concrete Quantity (Cum)"470 )471 472 material_btn = gr.Button("Calculate Materials")473 474 material_output = gr.Textbox(lines=20)475 476 material_btn.click(477 material_calculator,478 inputs=concrete_qty,479 outputs=material_output480 )481 482 # =====================================================483 # TAB 5 - PIPELINE ANALYZER484 # =====================================================485 486 with gr.Tab("🚰 Pipeline Analyzer"):487 488 diameter = gr.Number(489 label="Pipe Diameter (mm)"490 )491 492 pressure = gr.Number(493 label="Operating Pressure (Bar)"494 )495 496 pipeline_btn = gr.Button("Analyze Pipeline")497 498 pipeline_output = gr.Textbox(lines=20)499 500 pipeline_btn.click(501 pipeline_analyzer,502 inputs=[diameter, pressure],503 outputs=pipeline_output504 )505 506 # =====================================================507 # TAB 6 - INVENTORY MANAGEMENT508 # =====================================================509 510 with gr.Tab("📦 Inventory Management"):511 512 stock = gr.Number(513 label="Current Stock"514 )515 516 consumption = gr.Number(517 label="Daily Consumption"518 )519 520 inventory_btn = gr.Button("Analyze Inventory")521 522 inventory_output = gr.Textbox(lines=20)523 524 inventory_btn.click(525 inventory_helper,526 inputs=[stock, consumption],527 outputs=inventory_output528 )529 530 # =====================================================531 # TAB 7 - LABOUR ESTIMATOR532 # =====================================================533 534 with gr.Tab("👷 Labour Cost Estimator"):535 536 workers = gr.Number(537 label="No. of Workers"538 )539 540 daily_wage = gr.Number(541 label="Daily Wage"542 )543 544 days = gr.Number(545 label="Working Days"546 )547 548 labour_btn = gr.Button("Estimate Labour Cost")549 550 labour_output = gr.Textbox(lines=20)551 552 labour_btn.click(553 labour_estimator,554 inputs=[workers, daily_wage, days],555 outputs=labour_output556 )557 558 gr.Markdown("""559## ✅ Included Features560 561- Telangana SOR Tender Analysis562- Project Planning563- Financial Analysis564- Material Quantity Estimation565- Pipeline Pressure Analysis566- Inventory Management567- Labour Cost Estimation568- Multi-domain engineering utilities569""")570 571# =========================================================572# LAUNCH573# =========================================================574 575app.launch(server_name="0.0.0.0", server_port=7860)