Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# app.py -
|
2 |
|
3 |
import streamlit as st
|
4 |
import pandas as pd
|
@@ -6,11 +6,16 @@ import numpy as np
|
|
6 |
from sentence_transformers import SentenceTransformer
|
7 |
from transformers import pipeline
|
8 |
from sklearn.ensemble import IsolationForest
|
|
|
9 |
|
10 |
-
# Page
|
11 |
-
st.set_page_config(
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
#
|
14 |
st.markdown("""
|
15 |
<style>
|
16 |
html, body, [class*="css"] {
|
@@ -33,7 +38,7 @@ st.markdown("""
|
|
33 |
st.markdown("""
|
34 |
<div style='text-align: center;'>
|
35 |
<h1 style='color: #58a6ff;'>π FactoryGPT Humanization for the Factories of the Future in Industry 5.0 β Predict, Perfect, and Connect</h1>
|
36 |
-
<p style='color: #bbb;'>AI-Powered Digital Twin
|
37 |
<hr style='border-top: 2px solid #888;'>
|
38 |
</div>
|
39 |
""", unsafe_allow_html=True)
|
@@ -53,6 +58,7 @@ if uploaded_file:
|
|
53 |
st.markdown("### π§Ύ Sensor Log Preview")
|
54 |
st.dataframe(df.head(), use_container_width=True)
|
55 |
|
|
|
56 |
def convert_to_chunks(df):
|
57 |
return [f"[Log {i}] " + ", ".join([f"{col}: {row[col]:.2f}" for col in numeric_cols]) for i, row in df.iterrows()]
|
58 |
|
@@ -62,7 +68,7 @@ if uploaded_file:
|
|
62 |
st.session_state.chunks = chunks
|
63 |
st.session_state.embeddings = embeddings
|
64 |
|
65 |
-
# Condition
|
66 |
st.markdown("### βοΈ Equipment Condition Status")
|
67 |
iso = IsolationForest(contamination=0.02)
|
68 |
labels = iso.fit_predict(df[numeric_cols])
|
@@ -70,8 +76,41 @@ if uploaded_file:
|
|
70 |
df['maintenance'] = ['π§ Needs Maintenance' if x == -1 else 'π’ Stable' for x in labels]
|
71 |
st.dataframe(df[['status', 'maintenance'] + numeric_cols].head(), use_container_width=True)
|
72 |
|
73 |
-
#
|
74 |
-
st.markdown("###
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
roles = {
|
76 |
"Operator": "You are a machine operator. Check if equipment is running properly. If not, flag it immediately.",
|
77 |
"Maintenance": "You are a maintenance technician. Assess faulty logs and provide service insights.",
|
|
|
1 |
+
# app.py - FactoryGPT 5.0: Custom 3D Factory Layout + Real-Time Status and Role Chatbot
|
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 |
+
import pydeck as pdk
|
10 |
|
11 |
+
# Page configuration
|
12 |
+
st.set_page_config(
|
13 |
+
page_title="FactoryGPT Humanization for the Factories of the Future in Industry 5.0 β Predict, Perfect, and Connect",
|
14 |
+
page_icon="π§ ",
|
15 |
+
layout="wide"
|
16 |
+
)
|
17 |
|
18 |
+
# Dark theme styling
|
19 |
st.markdown("""
|
20 |
<style>
|
21 |
html, body, [class*="css"] {
|
|
|
38 |
st.markdown("""
|
39 |
<div style='text-align: center;'>
|
40 |
<h1 style='color: #58a6ff;'>π FactoryGPT Humanization for the Factories of the Future in Industry 5.0 β Predict, Perfect, and Connect</h1>
|
41 |
+
<p style='color: #bbb;'>AI-Powered Digital Twin | Real-Time Sensor Health with Custom 3D Layout</p>
|
42 |
<hr style='border-top: 2px solid #888;'>
|
43 |
</div>
|
44 |
""", unsafe_allow_html=True)
|
|
|
58 |
st.markdown("### π§Ύ Sensor Log Preview")
|
59 |
st.dataframe(df.head(), use_container_width=True)
|
60 |
|
61 |
+
# Prepare RAG chunks
|
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 |
st.session_state.chunks = chunks
|
69 |
st.session_state.embeddings = embeddings
|
70 |
|
71 |
+
# Condition Detection
|
72 |
st.markdown("### βοΈ Equipment Condition Status")
|
73 |
iso = IsolationForest(contamination=0.02)
|
74 |
labels = iso.fit_predict(df[numeric_cols])
|
|
|
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 |
+
# π§ Custom 3D Layout Visualization
|
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.",
|
116 |
"Maintenance": "You are a maintenance technician. Assess faulty logs and provide service insights.",
|