Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -2,10 +2,10 @@ import os
|
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
-
|
| 6 |
from langchain_community.llms import HuggingFaceHub
|
| 7 |
from langchain.agents.agent_types import AgentType
|
| 8 |
-
#
|
| 9 |
from langchain_experimental.agents import create_pandas_dataframe_agent
|
| 10 |
|
| 11 |
# Load environment variables
|
|
@@ -28,6 +28,26 @@ except Exception as e:
|
|
| 28 |
llm = None
|
| 29 |
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
def perform_eda(df: pd.DataFrame) -> str:
|
| 32 |
"""Performs a preliminary Exploratory Data Analysis and returns a summary string."""
|
| 33 |
|
|
@@ -94,7 +114,6 @@ def query_agent(df: pd.DataFrame, query: str) -> str:
|
|
| 94 |
|
| 95 |
try:
|
| 96 |
# Create the agent
|
| 97 |
-
# NOTE: LangChain requires allow_dangerous_code=True for the agent to execute python code
|
| 98 |
agent = create_pandas_dataframe_agent(
|
| 99 |
llm,
|
| 100 |
df,
|
|
|
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
| 5 |
+
from io import StringIO
|
| 6 |
from langchain_community.llms import HuggingFaceHub
|
| 7 |
from langchain.agents.agent_types import AgentType
|
| 8 |
+
# Correct import path for create_pandas_dataframe_agent
|
| 9 |
from langchain_experimental.agents import create_pandas_dataframe_agent
|
| 10 |
|
| 11 |
# Load environment variables
|
|
|
|
| 28 |
llm = None
|
| 29 |
|
| 30 |
|
| 31 |
+
def generate_eda_guide() -> str:
|
| 32 |
+
"""Generates a detailed, instructional guide on the steps of EDA using the LLM."""
|
| 33 |
+
if not llm:
|
| 34 |
+
return "LLM not initialized. Cannot fetch guide."
|
| 35 |
+
|
| 36 |
+
prompt = (
|
| 37 |
+
"Act as a professional data analyst. Generate a list of 5 key steps for Exploratory "
|
| 38 |
+
"Data Analysis (EDA) on a tabular dataset. For each step, provide a brief, actionable "
|
| 39 |
+
"description. Format the output using numbered lists and markdown for clarity. "
|
| 40 |
+
"DO NOT include any code blocks or concluding remarks."
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
try:
|
| 44 |
+
# Running the prompt directly through the LLM instance.
|
| 45 |
+
response = llm.invoke(prompt)
|
| 46 |
+
return response.strip()
|
| 47 |
+
except Exception as e:
|
| 48 |
+
return f"Error generating guide: {e}"
|
| 49 |
+
|
| 50 |
+
|
| 51 |
def perform_eda(df: pd.DataFrame) -> str:
|
| 52 |
"""Performs a preliminary Exploratory Data Analysis and returns a summary string."""
|
| 53 |
|
|
|
|
| 114 |
|
| 115 |
try:
|
| 116 |
# Create the agent
|
|
|
|
| 117 |
agent = create_pandas_dataframe_agent(
|
| 118 |
llm,
|
| 119 |
df,
|