Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files1 unmodified line234567789101119 unmodified lines313233333435363738394041424344454647343536373839404142514344534546474845 unmodified lines9495961059798991001 unmodified lineimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as snsimport osfrom io import StringIOimport openaiimport osfrom 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 "correlation" in query.lower(): # Correlation matrix sns.heatmap(data.corr(), annot=True, cmap="coolwarm", ax=ax) st.pyplot(fig) elif "histogram" in query.lower(): # Histogram column = 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 sold if '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')
if "bar" in query.lower() and "gross sales" in query.lower(): # Bar chart for countries and gross sales if '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 'units sold' columns.") st.error("The dataset must contain 'country' and 'gross_sales' columns.") else: st.error("Unsupported graph type. Try asking for a correlation matrix, histogram, or bar chart.") st.error("Unsupported graph type. Try asking for a bar chart.") except Exception as e: st.error(f"Error generating graph: {e}")
45 unmodified lines st.write("Dataset preview:", data.head())
# User input for graph generation query = st.text_input("Enter your query (e.g., 'Generate a bar chart for countries and units sold')") query = 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 queryapp.py+11-19