Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files65 unmodified lines66676869707172737475767778798065 unmodified lines"""Generate a graph based on user query."""try:fig, ax = plt.subplots(figsize=(10, 6))if "correlation" in query.lower():sns.heatmap(data.corr(), annot=True, cmap="coolwarm", ax=ax)st.pyplot(fig)elif "histogram" in query.lower():column = st.selectbox("Select a column for the histogram", data.columns)sns.histplot(data[column], kde=True, ax=ax)st.pyplot(fig)else:st.error("Unsupported graph type. Try asking for a correlation matrix or histogram.")except Exception as e:st.error(f"Error generating graph: {e}")65 unmodified lines66676869707172737475767778798081828384858687888990919265 unmodified lines"""Generate a graph based on user query."""try:fig, ax = plt.subplots(figsize=(10, 6))if "correlation" in query.lower():# Correlation matrixsns.heatmap(data.corr(), annot=True, cmap="coolwarm", ax=ax)st.pyplot(fig)elif "histogram" in query.lower():# Histogramcolumn = st.selectbox("Select a column for the histogram", data.columns)sns.histplot(data[column], kde=True, ax=ax)st.pyplot(fig)elif "bar" in query.lower() and "country" in query.lower():# Bar chart for countries and units soldif 'country' in data.columns and 'units sold' in data.columns:country_data = data[['country', 'units sold']].groupby('country').sum().reset_index()sns.barplot(x='country', y='units sold', data=country_data, ax=ax)ax.set_xticklabels(ax.get_xticklabels(), rotation=45, ha='right')st.pyplot(fig)else:st.error("The dataset must contain 'country' and 'units sold' columns.")else:st.error("Unsupported graph type. Try asking for a correlation matrix, histogram, or bar chart.")except Exception as e:st.error(f"Error generating graph: {e}")
app.py+13-1