Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -13,9 +13,6 @@ st.set_page_config(page_title="Smart Factory RAG Assistant", layout="wide")
|
|
13 |
|
14 |
st.title("π Industry 5.0 | Smart Factory RAG Assistant (Open Source)")
|
15 |
|
16 |
-
# Authenticate Hugging Face if using private token
|
17 |
-
# login(os.getenv("HUGGING_FACE_HUB_TOKEN")) # Uncomment if token is needed
|
18 |
-
|
19 |
# Load open-access model (Zephyr)
|
20 |
@st.cache_resource(show_spinner=True)
|
21 |
def load_model():
|
@@ -36,10 +33,12 @@ if uploaded_file:
|
|
36 |
df = pd.read_csv(uploaded_file)
|
37 |
st.success("β
File uploaded and loaded!")
|
38 |
|
39 |
-
#
|
40 |
-
st.subheader("π Data
|
41 |
-
|
42 |
-
st.
|
|
|
|
|
43 |
|
44 |
# Descriptive Stats
|
45 |
st.subheader("π Descriptive Statistics")
|
@@ -80,7 +79,7 @@ if uploaded_file:
|
|
80 |
# Pairplot
|
81 |
if len(numeric_columns) > 1:
|
82 |
st.subheader("π Pairwise Parameter Relationships")
|
83 |
-
sampled_df = df[numeric_columns].sample(n=
|
84 |
pair_fig = sns.pairplot(sampled_df)
|
85 |
st.pyplot(pair_fig)
|
86 |
|
@@ -111,8 +110,8 @@ if uploaded_file:
|
|
111 |
|
112 |
if question:
|
113 |
with st.spinner("Generating insights..."):
|
114 |
-
summary = df.describe().to_string()
|
115 |
-
corr_text = corr.to_string()
|
116 |
anomaly_count = len(anomalies)
|
117 |
|
118 |
context = f"""
|
@@ -120,24 +119,20 @@ You are a highly skilled {role} working in a smart manufacturing facility.
|
|
120 |
|
121 |
Here is a summary of the uploaded data:
|
122 |
|
123 |
-
|
124 |
{summary}
|
125 |
|
126 |
-
|
127 |
{corr_text}
|
128 |
|
129 |
-
|
130 |
-
{anomaly_count} anomalies detected using Isolation Forest method.
|
131 |
-
|
132 |
-
Based on this context, answer the following question in a clear, technically accurate manner and suggest best decisions from the point of view of a {role}.
|
133 |
|
134 |
QUESTION: {question}
|
135 |
-
|
136 |
"""
|
137 |
prompt = f"<s>[INST] {context} [/INST]"
|
138 |
-
output = nlp(prompt, max_new_tokens=
|
139 |
|
140 |
-
# Clean up response
|
141 |
if '[/INST]' in output:
|
142 |
answer = output.split('[/INST]')[-1].strip()
|
143 |
else:
|
|
|
13 |
|
14 |
st.title("π Industry 5.0 | Smart Factory RAG Assistant (Open Source)")
|
15 |
|
|
|
|
|
|
|
16 |
# Load open-access model (Zephyr)
|
17 |
@st.cache_resource(show_spinner=True)
|
18 |
def load_model():
|
|
|
33 |
df = pd.read_csv(uploaded_file)
|
34 |
st.success("β
File uploaded and loaded!")
|
35 |
|
36 |
+
# Data Summary
|
37 |
+
st.subheader("π Data Summary")
|
38 |
+
st.write(f"Number of rows: {df.shape[0]}")
|
39 |
+
st.write(f"Number of columns: {df.shape[1]}")
|
40 |
+
st.write("Column types:")
|
41 |
+
st.dataframe(df.dtypes.astype(str).rename("Type"))
|
42 |
|
43 |
# Descriptive Stats
|
44 |
st.subheader("π Descriptive Statistics")
|
|
|
79 |
# Pairplot
|
80 |
if len(numeric_columns) > 1:
|
81 |
st.subheader("π Pairwise Parameter Relationships")
|
82 |
+
sampled_df = df[numeric_columns].sample(n=100, random_state=1) if len(df) > 100 else df[numeric_columns]
|
83 |
pair_fig = sns.pairplot(sampled_df)
|
84 |
st.pyplot(pair_fig)
|
85 |
|
|
|
110 |
|
111 |
if question:
|
112 |
with st.spinner("Generating insights..."):
|
113 |
+
summary = df.describe().round(2).to_string()
|
114 |
+
corr_text = corr.round(2).to_string()
|
115 |
anomaly_count = len(anomalies)
|
116 |
|
117 |
context = f"""
|
|
|
119 |
|
120 |
Here is a summary of the uploaded data:
|
121 |
|
122 |
+
STATISTICS:
|
123 |
{summary}
|
124 |
|
125 |
+
CORRELATIONS:
|
126 |
{corr_text}
|
127 |
|
128 |
+
ANOMALIES: {anomaly_count} rows flagged.
|
|
|
|
|
|
|
129 |
|
130 |
QUESTION: {question}
|
131 |
+
Provide a short, focused response in your role.
|
132 |
"""
|
133 |
prompt = f"<s>[INST] {context} [/INST]"
|
134 |
+
output = nlp(prompt, max_new_tokens=250, do_sample=True, temperature=0.5)[0]['generated_text']
|
135 |
|
|
|
136 |
if '[/INST]' in output:
|
137 |
answer = output.split('[/INST]')[-1].strip()
|
138 |
else:
|