sialnoman318 commited on
Commit
fcaf4ec
·
verified ·
1 Parent(s): e66ec6d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +93 -0
app.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from groq import Groq
4
+
5
+ # Initialize Groq API
6
+ client = Groq(api_key="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") # Replace with your Groq API key
7
+
8
+ # Function to infer resources based on task types
9
+ def infer_resources(schedule):
10
+ resource_map = {
11
+ "Excavation": {"labor": 10, "equipment": "Excavator", "material": "Soil"},
12
+ "Foundation": {"labor": 15, "equipment": "Concrete Mixer", "material": "Concrete"},
13
+ "Framing": {"labor": 20, "equipment": "Cranes", "material": "Steel"},
14
+ "Finishing": {"labor": 5, "equipment": "Hand Tools", "material": "Paint"}
15
+ }
16
+
17
+ inferred_resources = []
18
+ for _, row in schedule.iterrows():
19
+ task = row["task"]
20
+ resources = resource_map.get(task, {"labor": 5, "equipment": "General", "material": "Standard"})
21
+ inferred_resources.append({
22
+ "task": task,
23
+ "labor": resources["labor"],
24
+ "equipment": resources["equipment"],
25
+ "material": resources["material"]
26
+ })
27
+
28
+ return pd.DataFrame(inferred_resources)
29
+
30
+ # Mock optimization logic
31
+ def mock_optimize_schedule(schedule_with_resources):
32
+ # Simulate a simple optimization process
33
+ optimized_schedule = []
34
+ conflicts = []
35
+
36
+ for _, row in schedule_with_resources.iterrows():
37
+ task = row["task"]
38
+ start_date = row["start_date"]
39
+ end_date = row["end_date"]
40
+ labor = row["labor"]
41
+ equipment = row["equipment"]
42
+ material = row["material"]
43
+
44
+ # Check for conflicts (mock logic)
45
+ if labor > 20: # Example conflict condition
46
+ conflicts.append(f"Task '{task}' exceeds labor capacity.")
47
+
48
+ optimized_schedule.append({
49
+ "task": task,
50
+ "start_date": start_date,
51
+ "end_date": end_date,
52
+ "labor": labor,
53
+ "equipment": equipment,
54
+ "material": material,
55
+ "conflict": "Yes" if f"Task '{task}' exceeds labor capacity." in conflicts else "No"
56
+ })
57
+
58
+ return pd.DataFrame(optimized_schedule), conflicts
59
+
60
+ # Main function for resource optimization
61
+ def optimize_resources(schedule_file):
62
+ try:
63
+ # Load schedule file
64
+ schedule = pd.read_csv(schedule_file.name)
65
+
66
+ # Infer resources
67
+ inferred_resources = infer_resources(schedule)
68
+ schedule_with_resources = pd.concat([schedule, inferred_resources], axis=1)
69
+
70
+ # Perform optimization (mocked for now)
71
+ optimized_schedule_df, conflicts = mock_optimize_schedule(schedule_with_resources)
72
+
73
+ return optimized_schedule_df, "\n".join(conflicts) if conflicts else "No conflicts detected."
74
+ except Exception as e:
75
+ return f"Error: {e}"
76
+
77
+ # Define Gradio interface
78
+ interface = gr.Interface(
79
+ fn=optimize_resources,
80
+ inputs=[
81
+ gr.File(label="Upload Schedule File (CSV)")
82
+ ],
83
+ outputs=[
84
+ gr.Dataframe(label="Optimized Schedule"), # Tabular output
85
+ gr.Textbox(label="Conflicts") # Text output for conflict details
86
+ ],
87
+ title="Intelligent Resource Loading",
88
+ description="Upload a construction schedule to generate an optimized schedule and resource allocation description. Resources are inferred automatically."
89
+ )
90
+
91
+ # Launch the app
92
+ if __name__ == "__main__":
93
+ interface.launch()