sammoftah commited on
Commit
cd819fa
·
verified ·
1 Parent(s): fa8823a

Add no-token fallback

Browse files
Files changed (1) hide show
  1. app.py +13 -0
app.py CHANGED
@@ -52,6 +52,19 @@ def safe_execute_code(code: str, df: pd.DataFrame, timeout: int = 5) -> tuple:
52
 
53
  def generate_analysis_code(question: str, df_info: str) -> str:
54
  """Generate pandas code using LLM"""
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  prompt = f"""You are a data analyst. Generate Python pandas code to answer this question.
57
 
 
52
 
53
  def generate_analysis_code(question: str, df_info: str) -> str:
54
  """Generate pandas code using LLM"""
55
+ if not os.getenv("HF_TOKEN"):
56
+ q = question.lower()
57
+ if "correlation" in q or "correlat" in q:
58
+ return "result = df.select_dtypes(include='number').corr()"
59
+ if "top" in q:
60
+ return "result = df.head(10)"
61
+ if "average" in q or "mean" in q:
62
+ return "result = df.select_dtypes(include='number').mean().sort_values(ascending=False)"
63
+ if "distribution" in q or "histogram" in q:
64
+ return "numeric_cols = df.select_dtypes(include='number').columns\nresult = df[numeric_cols].describe()\nfig = px.histogram(df, x=numeric_cols[0]) if len(numeric_cols) else None"
65
+ if "missing" in q or "null" in q:
66
+ return "result = df.isna().sum().sort_values(ascending=False)"
67
+ return "result = df.describe(include='all').transpose()"
68
 
69
  prompt = f"""You are a data analyst. Generate Python pandas code to answer this question.
70