Skip to content

AsmitaMishra24/Chat_with_CSV_Using_Gemini

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“Š Chat with Your CSV Using Gemini

Interact with your CSV data just like you're chatting with a data analyst!
This project lets you upload any CSV file and ask questions. Behind the scenes, it uses Gemini (Google's LLM) with LangChain agents to understand your query, reason through it, run Python code, and give the result β€” instantly!

Homepage


βš™οΈ How a Large Language Model (LLM) Works:

llm_diagram

  1. At its core, a Large Language Model like Gemini processes a prompt β€” which is a mix of instructions, examples, and the actual input β€” and generates a meaningful response. As shown below:

  2. Prompt = Instruction + Test Input: The prompt can contain a task description (e.g., "Summarize the data"), a few examples, and your actual input β€” such as a question about the CSV.

  3. LLM Reasoning: The model uses its pre-trained knowledge and the provided prompt to predict what comes next β€” effectively "thinking" about how to answer.

  4. Generated Output: The output might be plain text (a summary or explanation) or executable code (as in this project). The code is then executed to retrieve the final answer.

This mechanism allows the LLM to understand your intent, dynamically generate logic (like Python code), and provide relevant, accurate results from your data.


πŸ”§ Technologies Used

Component Description
🧠 Google Gemini (gemini-1.5-flash) The Large Language Model that understands and answers your questions
πŸ”— LangChain CSV Agent Translates your questions into Python code and runs it
πŸ“Š Pandas (indirect) Used internally to analyze CSV files
🎈 Streamlit Frontend to upload files and interact with the model
πŸ” dotenv Securely loads your API key from .env

🧠 How It Works

  1. Upload a CSV file through the UI.
  2. Ask a natural language question (e.g. "What is the mean area of the malignant tumors?")
  3. LangChain wraps the Gemini model with a Python code executor.
  4. Gemini thinks in steps: it figures out what to calculate, writes code, runs it, and returns the answer.
  5. The answer is shown on your screen with an optional explanation.

🧩 How the Agent Thinks (Step-by-Step)

It goes through:

  • 🧠 Thought
  • βš™οΈ Action (Python code)
  • πŸ“₯ Input (code to run)
  • πŸ‘€ Observation (what the code returns)
  • βœ… Final Answer

Here’s an actual screenshot showing the thought process of Gemini through LangChain:

Ques1

Ques2


πŸ–₯️ How It Appears on Screen

The user sees a simple Streamlit UI where they can upload a CSV and ask questions interactively:

Ques1

Ques2

Streamlit auto-refreshes results when the question is submitted. Great for rapid exploration.


πŸŽ₯ Demo Video

Recording.2025-06-21.003920.1.mp4

βš™οΈ Setup Instructions

Follow these steps to get the app running locally:

1. Clone the Repository

git clone https://github.com/AsmitaMishra24/Chat_with_CSV_Using_Gemini.git
cd Chat_with_CSV_Using_Gemini

2. Create a Virtual Environment

python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

3. Install Required Packages

pip install -r requirements.txt

4. Set Up Environment Variables

Create a .env file by copying the example:

cp .env.example .env

Then paste your actual Google API Key in .env:

GOOGLE_API_KEY=your_google_api_key_here

πŸ”‘ Get your key from Google AI Studio

5. Run the App

streamlit run app.py

Then go to: http://localhost:8501


.env.example

# .env.example
GOOGLE_API_KEY=your_google_api_key_here

βœ… Example Questions to Try

  • What is the total profit by category?

  • Which month had the highest revenue?

  • What’s the average number of orders per region?

  • Show top 5 performing products.


🀝 Contributing

Want to improve the project? Fix bugs? Add features?

  1. Fork the repo

  2. Create a new branch (git checkout -b feature-name)

  3. Commit changes (git commit -am 'Add feature')

  4. Push and open a PR


πŸ“¬ Contact

Made by Asmita Mishra

πŸ™‹β€β™€οΈ Have a suggestion or found a bug?

πŸ“© Want to connect or collaborate?

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages