Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,13 @@
|
|
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 |
-
#
|
9 |
def infer_resources(schedule):
|
10 |
resource_map = {
|
11 |
"Excavation": {"labor": 10, "equipment": "Excavator", "material": "Soil"},
|
@@ -27,9 +29,23 @@ def infer_resources(schedule):
|
|
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 |
|
@@ -63,6 +79,13 @@ def optimize_resources(schedule_file):
|
|
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)
|
@@ -84,10 +107,10 @@ interface = gr.Interface(
|
|
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
|
89 |
)
|
90 |
|
91 |
# Launch the app
|
92 |
if __name__ == "__main__":
|
93 |
-
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
+
import random
|
4 |
+
from datetime import datetime, timedelta
|
5 |
from groq import Groq
|
6 |
|
7 |
# Initialize Groq API
|
8 |
client = Groq(api_key="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") # Replace with your Groq API key
|
9 |
|
10 |
+
# Predefined resource inference logic
|
11 |
def infer_resources(schedule):
|
12 |
resource_map = {
|
13 |
"Excavation": {"labor": 10, "equipment": "Excavator", "material": "Soil"},
|
|
|
29 |
|
30 |
return pd.DataFrame(inferred_resources)
|
31 |
|
32 |
+
# Fill missing columns
|
33 |
+
def fill_missing_columns(schedule):
|
34 |
+
# Generate random dates if missing
|
35 |
+
if "start_date" not in schedule.columns:
|
36 |
+
schedule["start_date"] = [
|
37 |
+
(datetime.now() + timedelta(days=random.randint(1, 30))).strftime("%Y-%m-%d")
|
38 |
+
for _ in range(len(schedule))
|
39 |
+
]
|
40 |
+
if "end_date" not in schedule.columns:
|
41 |
+
schedule["end_date"] = [
|
42 |
+
(datetime.strptime(start, "%Y-%m-%d") + timedelta(days=random.randint(5, 15))).strftime("%Y-%m-%d")
|
43 |
+
for start in schedule["start_date"]
|
44 |
+
]
|
45 |
+
return schedule
|
46 |
+
|
47 |
# Mock optimization logic
|
48 |
def mock_optimize_schedule(schedule_with_resources):
|
|
|
49 |
optimized_schedule = []
|
50 |
conflicts = []
|
51 |
|
|
|
79 |
# Load schedule file
|
80 |
schedule = pd.read_csv(schedule_file.name)
|
81 |
|
82 |
+
# Ensure the 'task' column exists
|
83 |
+
if "task" not in schedule.columns:
|
84 |
+
raise ValueError("The uploaded schedule must contain a 'task' column.")
|
85 |
+
|
86 |
+
# Fill missing columns
|
87 |
+
schedule = fill_missing_columns(schedule)
|
88 |
+
|
89 |
# Infer resources
|
90 |
inferred_resources = infer_resources(schedule)
|
91 |
schedule_with_resources = pd.concat([schedule, inferred_resources], axis=1)
|
|
|
107 |
gr.Dataframe(label="Optimized Schedule"), # Tabular output
|
108 |
gr.Textbox(label="Conflicts") # Text output for conflict details
|
109 |
],
|
110 |
+
title="Dynamic Intelligent Resource Loading",
|
111 |
+
description="Upload a construction schedule with at least a 'task' column. The app will dynamically infer other details and optimize the schedule."
|
112 |
)
|
113 |
|
114 |
# Launch the app
|
115 |
if __name__ == "__main__":
|
116 |
+
interface.launch()
|