Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files3 unmodified lines45678919 unmodified lines2930313233345 unmodified lines4041424344453 unmodified linesimport seaborn as snsimport osfrom io import StringIO# Function to load the uploaded file (CSV or Excel)def load_file(uploaded_file):19 unmodified linesreturn columnreturn None# Function to generate graph based on user querydef generate_graph(data, query):"""Generate a graph based on user query."""5 unmodified linessales_col = infer_column(data, {"gross_sales", "sales", "revenue"})date_col = infer_column(data, {"date", "time"})if "bar" in query.lower() and country_col and sales_col:# Bar chart for countries and gross salescountry_data = data[[country_col, sales_col]].groupby(country_col).sum().reset_index()3 unmodified lines4567891011121319 unmodified lines33343536373839404142434445465 unmodified lines52535455565758593 unmodified linesimport seaborn as snsimport osfrom io import StringIOfrom transformers import pipeline# Load a lightweight NLP model for query understandingnlp = pipeline("text-classification", model="distilbert-base-uncased", tokenizer="distilbert-base-uncased")# Function to load the uploaded file (CSV or Excel)def load_file(uploaded_file):19 unmodified linesreturn columnreturn None# Function to classify the user querydef classify_query(query):"""Classify the user query into graph types."""results = nlp(query)if results:return results[0]['label']return None# Function to generate graph based on user querydef generate_graph(data, query):"""Generate a graph based on user query."""5 unmodified linessales_col = infer_column(data, {"gross_sales", "sales", "revenue"})date_col = infer_column(data, {"date", "time"})query_type = classify_query(query)if "bar" in query.lower() and country_col and sales_col:# Bar chart for countries and gross salescountry_data = data[[country_col, sales_col]].groupby(country_col).sum().reset_index()
app.py+14