Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files1 unmodified line234567891019 unmodified lines30313233343536373839404142434445464748495051525354555645 unmodified lines1021031041051061071081 unmodified lineimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsfrom io import StringIOimport openaiimport os# Groq API key from secretsGROQ_API_KEY = os.getenv("HUGGINGFACE_KEY")19 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, color='skyblue')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}")45 unmodified linesst.write("Dataset preview:", data.head())# User input for graph generationquery = st.text_input("Enter your query (e.g., 'Generate a bar chart for countries and units sold')")if query:# Generate the graph based on the query1 unmodified line23456789101119 unmodified lines31323334353637383940414243444546474845 unmodified lines9495969798991001 unmodified lineimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsimport osfrom io import StringIOimport openaifrom groq import Groq# Groq API key from secretsGROQ_API_KEY = os.getenv("HUGGINGFACE_KEY")19 unmodified lines"""Generate a graph based on user query."""try:fig, ax = plt.subplots(figsize=(10, 6))if "bar" in query.lower() and "gross sales" in query.lower():# Bar chart for countries and gross salesif 'country' in data.columns and 'gross_sales' in data.columns:country_data = data[['country', 'gross_sales']].groupby('country').sum().reset_index()sns.barplot(x='country', y='gross_sales', data=country_data, ax=ax, color='skyblue')ax.set_xticklabels(ax.get_xticklabels(), rotation=45, ha='right')st.pyplot(fig)else:st.error("The dataset must contain 'country' and 'gross_sales' columns.")else:st.error("Unsupported graph type. Try asking for a bar chart.")except Exception as e:st.error(f"Error generating graph: {e}")45 unmodified linesst.write("Dataset preview:", data.head())# User input for graph generationquery = st.text_input("Enter your query (e.g., 'Generate a bar chart for countries and gross sales')")if query:# Generate the graph based on the query
app.py+11-19