Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# app.py - FactoryGPT 5.0:
|
2 |
|
3 |
import streamlit as st
|
4 |
import pandas as pd
|
@@ -6,19 +6,18 @@ import numpy as np
|
|
6 |
from sentence_transformers import SentenceTransformer
|
7 |
from transformers import pipeline
|
8 |
from sklearn.ensemble import IsolationForest
|
9 |
-
import pydeck as pdk
|
10 |
|
11 |
-
# Page
|
12 |
st.set_page_config(
|
13 |
-
page_title="FactoryGPT
|
14 |
page_icon="π§ ",
|
15 |
layout="wide"
|
16 |
)
|
17 |
|
18 |
-
# Dark
|
19 |
st.markdown("""
|
20 |
<style>
|
21 |
-
html, body, [class*="css"]
|
22 |
font-family: 'Segoe UI', sans-serif;
|
23 |
background-color: #0f1117;
|
24 |
color: #f0f0f0;
|
@@ -34,11 +33,11 @@ st.markdown("""
|
|
34 |
</style>
|
35 |
""", unsafe_allow_html=True)
|
36 |
|
37 |
-
#
|
38 |
st.markdown("""
|
39 |
<div style='text-align: center;'>
|
40 |
-
<h1 style='color: #58a6ff;'>π FactoryGPT
|
41 |
-
<p style='color: #bbb;'>AI-Powered
|
42 |
<hr style='border-top: 2px solid #888;'>
|
43 |
</div>
|
44 |
""", unsafe_allow_html=True)
|
@@ -58,7 +57,7 @@ if uploaded_file:
|
|
58 |
st.markdown("### π§Ύ Sensor Log Preview")
|
59 |
st.dataframe(df.head(), use_container_width=True)
|
60 |
|
61 |
-
#
|
62 |
def convert_to_chunks(df):
|
63 |
return [f"[Log {i}] " + ", ".join([f"{col}: {row[col]:.2f}" for col in numeric_cols]) for i, row in df.iterrows()]
|
64 |
|
@@ -68,7 +67,7 @@ if uploaded_file:
|
|
68 |
st.session_state.chunks = chunks
|
69 |
st.session_state.embeddings = embeddings
|
70 |
|
71 |
-
#
|
72 |
st.markdown("### βοΈ Equipment Condition Status")
|
73 |
iso = IsolationForest(contamination=0.02)
|
74 |
labels = iso.fit_predict(df[numeric_cols])
|
@@ -76,40 +75,7 @@ if uploaded_file:
|
|
76 |
df['maintenance'] = ['π§ Needs Maintenance' if x == -1 else 'π’ Stable' for x in labels]
|
77 |
st.dataframe(df[['status', 'maintenance'] + numeric_cols].head(), use_container_width=True)
|
78 |
|
79 |
-
#
|
80 |
-
st.markdown("### π§ 3D Digital Factory Layout (Custom Zones)")
|
81 |
-
zones = ["Assembly", "Packaging", "Inspection", "Robotics", "Warehouse"]
|
82 |
-
df['zone'] = np.random.choice(zones, size=len(df))
|
83 |
-
|
84 |
-
zone_coords = {
|
85 |
-
"Assembly": [0, 0],
|
86 |
-
"Packaging": [10, 5],
|
87 |
-
"Inspection": [5, 15],
|
88 |
-
"Robotics": [15, 10],
|
89 |
-
"Warehouse": [20, 0]
|
90 |
-
}
|
91 |
-
|
92 |
-
df['lat'] = df['zone'].map(lambda z: zone_coords[z][1] + np.random.rand() * 0.5)
|
93 |
-
df['lon'] = df['zone'].map(lambda z: zone_coords[z][0] + np.random.rand() * 0.5)
|
94 |
-
df['value'] = df[numeric_cols[0]] if numeric_cols else 0
|
95 |
-
|
96 |
-
view_state = pdk.ViewState(latitude=10, longitude=10, zoom=2, pitch=45)
|
97 |
-
layer = pdk.Layer(
|
98 |
-
"ScatterplotLayer",
|
99 |
-
data=df.head(500),
|
100 |
-
get_position='[lon, lat]',
|
101 |
-
get_color='[255, 140, 0, 180]',
|
102 |
-
get_radius='value',
|
103 |
-
pickable=True
|
104 |
-
)
|
105 |
-
|
106 |
-
st.pydeck_chart(pdk.Deck(
|
107 |
-
layers=[layer],
|
108 |
-
initial_view_state=view_state,
|
109 |
-
tooltip={"text": "Zone: {zone}\nStatus: {status}\nMaintenance: {maintenance}"}
|
110 |
-
))
|
111 |
-
|
112 |
-
# π¬ Role-based Chat Assistant
|
113 |
st.markdown("### π¬ Role-Based Chat Assistant")
|
114 |
roles = {
|
115 |
"Operator": "You are a machine operator. Check if equipment is running properly. If not, flag it immediately.",
|
|
|
1 |
+
# app.py - FactoryGPT 5.0: Predictive Maintenance + Role Chat (No 3D Map)
|
2 |
|
3 |
import streamlit as st
|
4 |
import pandas as pd
|
|
|
6 |
from sentence_transformers import SentenceTransformer
|
7 |
from transformers import pipeline
|
8 |
from sklearn.ensemble import IsolationForest
|
|
|
9 |
|
10 |
+
# Page setup
|
11 |
st.set_page_config(
|
12 |
+
page_title="FactoryGPT 5.0 β Predict, Perfect, and Connect",
|
13 |
page_icon="π§ ",
|
14 |
layout="wide"
|
15 |
)
|
16 |
|
17 |
+
# Dark mode CSS
|
18 |
st.markdown("""
|
19 |
<style>
|
20 |
+
html, body, [class*="css"] {
|
21 |
font-family: 'Segoe UI', sans-serif;
|
22 |
background-color: #0f1117;
|
23 |
color: #f0f0f0;
|
|
|
33 |
</style>
|
34 |
""", unsafe_allow_html=True)
|
35 |
|
36 |
+
# Title
|
37 |
st.markdown("""
|
38 |
<div style='text-align: center;'>
|
39 |
+
<h1 style='color: #58a6ff;'>π FactoryGPT 5.0 β Predict, Perfect, and Connect</h1>
|
40 |
+
<p style='color: #bbb;'>AI-Powered Predictive Maintenance | Human-in-the-Loop Decision Support</p>
|
41 |
<hr style='border-top: 2px solid #888;'>
|
42 |
</div>
|
43 |
""", unsafe_allow_html=True)
|
|
|
57 |
st.markdown("### π§Ύ Sensor Log Preview")
|
58 |
st.dataframe(df.head(), use_container_width=True)
|
59 |
|
60 |
+
# RAG Embeddings
|
61 |
def convert_to_chunks(df):
|
62 |
return [f"[Log {i}] " + ", ".join([f"{col}: {row[col]:.2f}" for col in numeric_cols]) for i, row in df.iterrows()]
|
63 |
|
|
|
67 |
st.session_state.chunks = chunks
|
68 |
st.session_state.embeddings = embeddings
|
69 |
|
70 |
+
# Equipment condition via Isolation Forest
|
71 |
st.markdown("### βοΈ Equipment Condition Status")
|
72 |
iso = IsolationForest(contamination=0.02)
|
73 |
labels = iso.fit_predict(df[numeric_cols])
|
|
|
75 |
df['maintenance'] = ['π§ Needs Maintenance' if x == -1 else 'π’ Stable' for x in labels]
|
76 |
st.dataframe(df[['status', 'maintenance'] + numeric_cols].head(), use_container_width=True)
|
77 |
|
78 |
+
# Role-based Assistant
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
st.markdown("### π¬ Role-Based Chat Assistant")
|
80 |
roles = {
|
81 |
"Operator": "You are a machine operator. Check if equipment is running properly. If not, flag it immediately.",
|