Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,19 +4,19 @@ from transformers import pipeline
|
|
| 4 |
from langchain_community.llms import HuggingFacePipeline
|
| 5 |
from langchain_experimental.agents import create_pandas_dataframe_agent
|
| 6 |
|
| 7 |
-
# Load
|
| 8 |
df = pd.read_csv("synthetic_profit.csv")
|
| 9 |
|
| 10 |
-
#
|
| 11 |
hf_pipeline = pipeline(
|
| 12 |
task="text2text-generation",
|
| 13 |
model="google/flan-t5-base",
|
| 14 |
-
device=-1 # CPU
|
| 15 |
)
|
| 16 |
|
| 17 |
-
# LangChain agent setup
|
| 18 |
llm = HuggingFacePipeline(pipeline=hf_pipeline)
|
| 19 |
-
agent = create_pandas_dataframe_agent(llm, df, verbose=True)
|
| 20 |
|
| 21 |
def answer(query: str) -> str:
|
| 22 |
try:
|
|
|
|
| 4 |
from langchain_community.llms import HuggingFacePipeline
|
| 5 |
from langchain_experimental.agents import create_pandas_dataframe_agent
|
| 6 |
|
| 7 |
+
# Load data
|
| 8 |
df = pd.read_csv("synthetic_profit.csv")
|
| 9 |
|
| 10 |
+
# Set up lightweight Hugging Face pipeline (Flan-T5 Base)
|
| 11 |
hf_pipeline = pipeline(
|
| 12 |
task="text2text-generation",
|
| 13 |
model="google/flan-t5-base",
|
| 14 |
+
device=-1 # CPU
|
| 15 |
)
|
| 16 |
|
| 17 |
+
# LangChain agent setup (with explicit security opt-in)
|
| 18 |
llm = HuggingFacePipeline(pipeline=hf_pipeline)
|
| 19 |
+
agent = create_pandas_dataframe_agent(llm, df, verbose=True, allow_dangerous_code=True)
|
| 20 |
|
| 21 |
def answer(query: str) -> str:
|
| 22 |
try:
|