Spaces:
Sleeping
Sleeping
mriusero
commited on
Commit
·
7528ee2
1
Parent(s):
49655be
feat: session state
Browse files- app.py +16 -2
- data/efficiency.json +0 -14
- data/tool_1.csv +0 -3
- data/tool_2.csv +0 -4
- data/tool_3.csv +0 -4
- data/tool_4.csv +0 -4
- data/tool_all.csv +0 -12
- src/production/processing.py +0 -24
- src/ui/session.py +51 -0
- src/ui/sidebar.py +13 -3
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
from src.ui import sidebar_ui, dashboard_ui
|
|
|
4 |
|
5 |
custom_theme = gr.themes.Base(
|
6 |
primary_hue="blue",
|
@@ -9,6 +10,14 @@ custom_theme = gr.themes.Base(
|
|
9 |
font=[gr.themes.GoogleFont("Open Sans"), "sans-serif"],
|
10 |
)
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
with gr.Blocks(theme=custom_theme) as demo:
|
13 |
|
14 |
# HEADER
|
@@ -20,11 +29,16 @@ with gr.Blocks(theme=custom_theme) as demo:
|
|
20 |
You can interact with the chatbot to get insights and assistance on production-related queries.
|
21 |
"""
|
22 |
)
|
|
|
|
|
|
|
23 |
# CHAT INTERFACE
|
24 |
-
sidebar_ui(width=700, visible=True)
|
25 |
|
26 |
# DASHBOARD
|
27 |
-
|
|
|
|
|
28 |
|
29 |
# DESCRIPTION
|
30 |
with gr.Tab("Description"):
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
from src.ui import sidebar_ui, dashboard_ui
|
4 |
+
from src.ui.session import session_state
|
5 |
|
6 |
custom_theme = gr.themes.Base(
|
7 |
primary_hue="blue",
|
|
|
10 |
font=[gr.themes.GoogleFont("Open Sans"), "sans-serif"],
|
11 |
)
|
12 |
|
13 |
+
STATE = {
|
14 |
+
"running": False,
|
15 |
+
"current_time": None,
|
16 |
+
"part_id": None,
|
17 |
+
"data": {},
|
18 |
+
"machine": {},
|
19 |
+
}
|
20 |
+
|
21 |
with gr.Blocks(theme=custom_theme) as demo:
|
22 |
|
23 |
# HEADER
|
|
|
29 |
You can interact with the chatbot to get insights and assistance on production-related queries.
|
30 |
"""
|
31 |
)
|
32 |
+
|
33 |
+
state = gr.State(STATE)
|
34 |
+
|
35 |
# CHAT INTERFACE
|
36 |
+
sidebar_ui(state, width=700, visible=True)
|
37 |
|
38 |
# DASHBOARD
|
39 |
+
with gr.Tab("Dashboard"):
|
40 |
+
session_state(state)
|
41 |
+
dashboard_ui(state)
|
42 |
|
43 |
# DESCRIPTION
|
44 |
with gr.Tab("Description"):
|
data/efficiency.json
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"opening_time": "0 days 08:30:15",
|
3 |
-
"required_time": "0 days 08:30:15",
|
4 |
-
"unplanned_stop_time": "0 days 08:30:00",
|
5 |
-
"operating_time": "0 days 00:00:15",
|
6 |
-
"net_time": "0 days 00:00:15",
|
7 |
-
"useful_time": "0 days 00:00:08",
|
8 |
-
"quality_rate": 56.25,
|
9 |
-
"operating_rate": 100.0,
|
10 |
-
"availability_rate": 0.04899559039686428,
|
11 |
-
"TRS": 0.02756001959823616,
|
12 |
-
"MTBF": "0 days 00:00:03",
|
13 |
-
"MTTR": "0 days 01:42:00"
|
14 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data/tool_1.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
Part ID,Timestamp,Position,Orientation,Tool ID,Compliance,Event,Error Code,Error Description,Downtime Start,Downtime End,pos_rolling_mean,pos_rolling_std,pos_rolling_cp,pos_rolling_cpk,ori_rolling_mean,ori_rolling_std,ori_rolling_cp,ori_rolling_cpk
|
2 |
-
4,2025-06-06 16:24:31,0.3607,0.3622,1,OK,N/A,N/A,N/A,N/A,N/A,0.3607,,,,0.3622,,,
|
3 |
-
8,2025-06-06 21:39:38,0.3889,0.2458,1,OK,N/A,N/A,N/A,N/A,N/A,0.3748,0.019940411229460643,1.6716472368476298,1.2503921331620276,0.304,0.08230722933011414,0.8099734034210165,0.42118616977892853
|
|
|
|
|
|
|
|
data/tool_2.csv
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
Part ID,Timestamp,Position,Orientation,Tool ID,Compliance,Event,Error Code,Error Description,Downtime Start,Downtime End,pos_rolling_mean,pos_rolling_std,pos_rolling_cp,pos_rolling_cpk,ori_rolling_mean,ori_rolling_std,ori_rolling_cp,ori_rolling_cpk
|
2 |
-
1,2025-06-06 16:09:27,0.3956,0.4285,2,OK,N/A,N/A,N/A,N/A,N/A,0.3956,,,,0.4285,,,
|
3 |
-
5,2025-06-06 19:24:33,0.4054,0.3711,2,OK,N/A,N/A,N/A,N/A,N/A,0.40049999999999997,0.006929646455628168,4.810250212153383,4.786198961092618,0.3998,0.04058792924010783,1.6425244626865212,1.6408819382238347
|
4 |
-
9,2025-06-06 21:39:39,0.3808,0.5243,2,OK,N/A,N/A,N/A,N/A,N/A,0.3939333333333333,0.01238439878772209,2.6915584603412515,2.528270580413882,0.4413,0.07739793278893178,0.8613494477749186,0.6834807868093978
|
|
|
|
|
|
|
|
|
|
data/tool_3.csv
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
Part ID,Timestamp,Position,Orientation,Tool ID,Compliance,Event,Error Code,Error Description,Downtime Start,Downtime End,pos_rolling_mean,pos_rolling_std,pos_rolling_cp,pos_rolling_cpk,ori_rolling_mean,ori_rolling_std,ori_rolling_cp,ori_rolling_cpk
|
2 |
-
2,2025-06-06 16:09:28,0.3741,0.3253,3,OK,N/A,N/A,N/A,N/A,N/A,0.3741,,,,0.3253,,,
|
3 |
-
6,2025-06-06 19:39:35,0.4245,0.3435,3,OK,N/A,N/A,N/A,N/A,N/A,0.3993,0.035638181771801995,0.935326430140936,0.9287791451299494,0.33440000000000003,0.012869343417595179,5.1802694592421,3.481141076610692
|
4 |
-
10,2025-06-06 21:39:40,0.3902,0.4416,3,OK,N/A,N/A,N/A,N/A,N/A,0.3962666666666667,0.025741859554689,1.294907745981448,1.246564523464808,0.37013333333333337,0.06255736034499322,1.065688614401428,0.9065457813174815
|
|
|
|
|
|
|
|
|
|
data/tool_4.csv
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
Part ID,Timestamp,Position,Orientation,Tool ID,Compliance,Event,Error Code,Error Description,Downtime Start,Downtime End,pos_rolling_mean,pos_rolling_std,pos_rolling_cp,pos_rolling_cpk,ori_rolling_mean,ori_rolling_std,ori_rolling_cp,ori_rolling_cpk
|
2 |
-
3,2025-06-06 16:24:30,0.3412,0.9907,4,NOK,N/A,N/A,N/A,N/A,N/A,0.3412,,,,0.9907,,,
|
3 |
-
7,2025-06-06 21:39:37,0.395,0.3865,4,OK,N/A,N/A,N/A,N/A,N/A,0.3681,0.038042344827836284,0.876216581395969,0.5967034919306549,0.6886,0.42723391719291204,0.15604254246641233,-0.06912684631262067
|
4 |
-
11,2025-06-07 00:39:42,0.6491,0.5659,4,NOK,N/A,N/A,N/A,N/A,N/A,0.46176666666666666,0.16445042819443598,0.20269532709225951,0.0774971800582739,0.6477,0.310294763088261,0.21484947410376964,-0.051241599573749144
|
|
|
|
|
|
|
|
|
|
data/tool_all.csv
DELETED
@@ -1,12 +0,0 @@
|
|
1 |
-
Part ID,Timestamp,Position,Orientation,Tool ID,Compliance,Event,Error Code,Error Description,Downtime Start,Downtime End,pos_rolling_mean,pos_rolling_std,pos_rolling_cp,pos_rolling_cpk,ori_rolling_mean,ori_rolling_std,ori_rolling_cp,ori_rolling_cpk
|
2 |
-
1,2025-06-06 16:09:27,0.3956,0.4285,2,OK,N/A,N/A,N/A,N/A,N/A,0.3956,,,,0.4285,,,
|
3 |
-
2,2025-06-06 16:09:28,0.3741,0.3253,3,OK,N/A,N/A,N/A,N/A,N/A,0.38485,0.015202795795510805,2.19257916646991,1.8604034227497193,0.3769,0.07297341981845173,0.9135746526957974,0.8080567803094328
|
4 |
-
3,2025-06-06 16:24:30,0.3412,0.9907,4,NOK,N/A,N/A,N/A,N/A,N/A,0.3703,0.02739835761501045,1.2166179375318231,0.8552824100848719,0.5815,0.35811456267513053,0.1861601666479685,0.017219815414937053
|
5 |
-
4,2025-06-06 16:24:31,0.3607,0.3622,1,OK,N/A,N/A,N/A,N/A,N/A,0.3679,0.022879831001706884,1.4568872178665393,0.9892264209313804,0.526675,0.3122826964466651,0.2134817824530111,0.07826775849183518
|
6 |
-
5,2025-06-06 19:24:33,0.4054,0.3711,2,OK,N/A,N/A,N/A,N/A,N/A,0.3754,0.02595890983843505,1.2840806313052342,0.9681967960041469,0.49555999999999994,0.2792509230065319,0.2387339169693891,0.12466685144141502
|
7 |
-
6,2025-06-06 19:39:35,0.4245,0.3435,3,OK,N/A,N/A,N/A,N/A,N/A,0.38358333333333333,0.03067399006759092,1.0866970113729086,0.9082975853391895,0.47021666666666667,0.257368548324512,0.25903191007864607,0.1680901236485347
|
8 |
-
7,2025-06-06 21:39:37,0.395,0.3865,4,OK,N/A,N/A,N/A,N/A,N/A,0.3852142857142857,0.028331927135973208,1.1765289799510255,1.0025707664868377,0.4582571428571428,0.2370654330007003,0.28121631155930576,0.19930201737795947
|
9 |
-
8,2025-06-06 21:39:38,0.3889,0.2458,1,OK,N/A,N/A,N/A,N/A,N/A,0.385675,0.026262616015926513,1.269231264437591,1.087413885806906,0.4317,0.23197780066204612,0.2873838206776912,0.24183348510027716
|
10 |
-
9,2025-06-06 21:39:39,0.3808,0.5243,2,OK,N/A,N/A,N/A,N/A,N/A,0.3851333333333333,0.024620113728413193,1.3539065538460338,1.15262577950759,0.4419888888888889,0.21917969479655525,0.30416442877405825,0.24030679675532682
|
11 |
-
10,2025-06-06 21:39:40,0.3902,0.4416,3,OK,N/A,N/A,N/A,N/A,N/A,0.38564,0.023267297030620273,1.4326259423028787,1.226900856988185,0.44195,0.2066446345783021,0.3226150381436844,0.25494653389304656
|
12 |
-
11,2025-06-07 00:39:42,0.6491,0.5659,4,NOK,N/A,N/A,N/A,N/A,N/A,0.40959090909090906,0.08244596357063765,0.4043052187118193,0.3655286727353676,0.45321818181818185,0.19957077851319724,0.33405024103896114,0.24516250871886658
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/production/processing.py
DELETED
@@ -1,24 +0,0 @@
|
|
1 |
-
import json
|
2 |
-
|
3 |
-
from .metrics.tools import get_tools_metrics
|
4 |
-
from .metrics.machine import get_machine_metrics
|
5 |
-
|
6 |
-
def process(raw_data):
|
7 |
-
"""
|
8 |
-
Process the raw production data to extract metrics.
|
9 |
-
"""
|
10 |
-
print("=== TOOLS METRICS ===\n")
|
11 |
-
tools_dfs = get_tools_metrics(raw_data)
|
12 |
-
tools_dfs = {tool: df for tool, df in tools_dfs.items() if not df.empty}
|
13 |
-
|
14 |
-
for tool, df in tools_dfs.items():
|
15 |
-
print(tool)
|
16 |
-
print(df.head())
|
17 |
-
print("\n")
|
18 |
-
|
19 |
-
print("=== MACHINE METRICS ===")
|
20 |
-
machine_results = get_machine_metrics(raw_data)
|
21 |
-
machine_json = json.dumps(machine_results, indent=4)
|
22 |
-
print(machine_json)
|
23 |
-
|
24 |
-
return tools_dfs, machine_json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/ui/session.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def show_toast(text):
|
4 |
+
gr.Info(text, duration=1.5)
|
5 |
+
return "Toast displayed"
|
6 |
+
|
7 |
+
def play_fn(state):
|
8 |
+
state['running'] = True
|
9 |
+
print("\n\n===== Production started =====\n\n")
|
10 |
+
show_toast("Production started !")
|
11 |
+
return state
|
12 |
+
|
13 |
+
def stop_fn(state):
|
14 |
+
state['running'] = False
|
15 |
+
print("\n\n----- Production stopped -----\n\n")
|
16 |
+
show_toast("Production paused !")
|
17 |
+
return state
|
18 |
+
|
19 |
+
def reset_fn(state):
|
20 |
+
state['running'] = False
|
21 |
+
state['current_time'] = None
|
22 |
+
state['part_id'] = None
|
23 |
+
state['data'] = {}
|
24 |
+
state['machine'] = {}
|
25 |
+
print("\n\n... production reinitialised successfully ...\n\n")
|
26 |
+
show_toast("Production reset !")
|
27 |
+
return state
|
28 |
+
|
29 |
+
def session_state(state):
|
30 |
+
"""
|
31 |
+
Session state management for production simulation controls.
|
32 |
+
"""
|
33 |
+
with gr.Row():
|
34 |
+
play = gr.Button("▶️ Play")
|
35 |
+
stop = gr.Button("⏸️ Pause")
|
36 |
+
reset = gr.Button("🔄 Reset")
|
37 |
+
play.click(
|
38 |
+
fn=play_fn,
|
39 |
+
inputs=state,
|
40 |
+
outputs=state
|
41 |
+
)
|
42 |
+
stop.click(
|
43 |
+
fn=stop_fn,
|
44 |
+
inputs=state,
|
45 |
+
outputs=state
|
46 |
+
)
|
47 |
+
reset.click(
|
48 |
+
fn=reset_fn,
|
49 |
+
inputs=state,
|
50 |
+
outputs=state
|
51 |
+
)
|
src/ui/sidebar.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
from src.chat import respond
|
4 |
|
5 |
-
|
|
|
6 |
with gr.Sidebar(width=width, visible=visible):
|
7 |
gr.Markdown("# Ask Agent")
|
8 |
gr.Markdown(
|
@@ -21,4 +21,14 @@ def sidebar_ui(width=700, visible=True):
|
|
21 |
"""
|
22 |
)
|
23 |
gr.HTML("<div style='margin-bottom: 40px;'></div>")
|
24 |
-
chatbot = gr.ChatInterface(respond, type='messages')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from src.chat import respond
|
3 |
|
4 |
+
|
5 |
+
def sidebar_ui(state, width=700, visible=True):
|
6 |
with gr.Sidebar(width=width, visible=visible):
|
7 |
gr.Markdown("# Ask Agent")
|
8 |
gr.Markdown(
|
|
|
21 |
"""
|
22 |
)
|
23 |
gr.HTML("<div style='margin-bottom: 40px;'></div>")
|
24 |
+
chatbot = gr.ChatInterface(respond, type='messages')
|
25 |
+
sessions_state = gr.JSON(
|
26 |
+
label="Sessions State",
|
27 |
+
visible=True,
|
28 |
+
value=state.value,
|
29 |
+
)
|
30 |
+
state.change(
|
31 |
+
fn=lambda x: x,
|
32 |
+
inputs=state,
|
33 |
+
outputs=sessions_state,
|
34 |
+
)
|