csv-agent / app.py
umair894's picture
Update app.py
117896a
import gradio as gr
from langchain.llms import OpenAI
from langchain.chat_models import ChatOpenAI
from langchain.agents.agent_types import AgentType
from langchain_experimental.agents.agent_toolkits import create_csv_agent
import os
spaces_key = os.getenv("open_ai")
def call_csv(file_path):
# Set up the agent
agent = create_csv_agent(
ChatOpenAI(temperature=0, model="gpt-3.5-turbo-16k", openai_api_key=spaces_key),
file_path,
verbose=True,
agent_type=AgentType.OPENAI_FUNCTIONS,)
return agent
# Define the Gradio function
def qa_app(csv_file, question):
# Update the agent with the new CSV file
agent = call_csv(csv_file)
# Perform QA using the provided question
response = agent.run(question)
return response
# Set up the Gradio interface
iface = gr.Interface(
fn=qa_app,
inputs=["file", "text"],
outputs="text",
live=False,
title="CSV QA App",
description="Upload a CSV file and ask a question about the data.",
)
iface.launch()