def displaygraph(predictionsdf, uploadedfile): def getbase64(binfile): with…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
def display_graph(predictions_df, uploaded_file):
def get_base64(bin_file):
with open(bin_file, "rb") as f:
data = f.read()
return base64.b64encode(data).decode()
def set_background(png_file):
bin_str = get_base64(png_file)
page_bg_img = (
"""
<style>
.stApp {
background-image: url("data:image/png;base64,%s");
background-size: cover;
}
</style>
"""
% bin_str
)
st.markdown(page_bg_img, unsafe_allow_html=True)
set_background("Screenshot (32).png")
st.markdown('<div style="margin-top: 50px;"></div>', unsafe_allow_html=True)# ... (previous code)
st.subheader("Early warning Signal:")
df_status_1 = predictions_df[predictions_df["Predicted_Status"] == 1].head(10)
df_status_0 = predictions_df[predictions_df["Predicted_Status"] == 0].head(10)
# Combine the DataFrames
df_combined = pd.concat([df_status_0, df_status_1])
start_timestamp = datetime.datetime(2023, 1, 1)
df_combined["Synthetic_Timestamp"] = pd.date_range(
start=start_timestamp, periods=len(df_combined), freq="T"
)
# df_combined['Synthetic_Timestamp'] = pd.date_range(start='2023-01-01', periods=len(df_combined), freq='T')
instance_to_explain = predictions_df.drop(['Predicted_Status'],axis=1)
Rules=""
for i in predictions_df.iterrows:
# Exclude prediction-related columns
explainer = LimeTabularExplainer(predictions_df.iloc[:, :-1].values, feature_names=predictions_df.columns[:-1].tolist(),
class_names=['likely_to_fail', 'Normal'], verbose=True, mode='classification',
discretize_continuous=True)
exp = explainer.explain_instance(instance_to_explain, model.predict_proba)
#st.write("### Decision Rule for Instance", instance_number)
Rules=exp.as_list()
predictions_df['Rules']=Rules
fig = px.scatter(
df_combined,
x="Synthetic_Timestamp",
y="Predicted_Status",
color_discrete_map={1: "red", 0: "green"},
symbol_map={1: "circle", 0: "circle"},
hue=Predicted_Status,hover_name="Predicted_Status",hover_data=["Rules"])
fig.update_layout(xaxis_tickangle=-45)
# Get the index of the clicked point
point_index = st.plotly_chart(fig, use_container_width=True, config={"displayModeBar": True}) this is my piece of my code TypeError: 'method' object is not iterable
Traceback: File "/usr/local/lib/python3.10/dist-packages/streamlit/runtime/scriptrunner/script_runner.py", line 534, in _run_script exec(code, module.dict) File "/content/app.py", line 252, in display_graph( File "/content/app.py", line 112, in display_graph for i in predictions_df.iterrows: getting error an i'm calling the function display_graph( st.session_state.predictions_df, st.session_state.uploaded_file ) like this
The error you're experiencing is related to the st.plotly_chart() function. The function st.plotly_chart() expects a list of figures, but it seems that it is receiving a method object.
This is probably because you are trying to call st.plotly_chart() on a single figure object returned by fig. To fix the issue, you should create a list of figures and pass it to st.plotly_chart().
Here's an updated version of your code that creates a list of figures and passes it to st.plotly_chart():
def display_graph(predictions_df, uploaded_file):
def get_base64(bin_file):
with open(bin_file, "rb") as f:
data = f.read()
return base64.b64encode(data).decode()
def set_background(png_file):
bin_str = get_base64(png_file)
page_bg_img = (
"""
<style>
.stApp {
background-image: url("data:image/png;base64,%s");
background-size: cover;
}
</style>
"""
% bin_str
)
st.markdown(page_bg_img, unsafe_allow_html=True)
set_background("Screenshot (32).png")
st.markdown('<div style="margin-top: 50px;"></div>', unsafe_allow_html=True)# ... (previous code)
st.subheader("Early warning Signal:")
df_status_1 = predictions_df[predictions_df["Predicted_Status"] == 1].head(10)
df_status_0 = predictions_df[predictions_df["Predicted_Status"] == 0].head(10)
# Combine the DataFrames
df_combined = pd.concat([df_status_0, df_status_1])
start_timestamp = datetime.datetime(2023, 1, 1)
df_combined
Not yet included in a published release.