add to github
Browse files
README.md
CHANGED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Data Analyst Agent with OpenAI Assistants
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: orange
|
| 5 |
+
colorTo: red
|
| 6 |
+
sdk: gradio
|
| 7 |
+
python_version: '3.11'
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# π€ Data Analyst Agent with OpenAI Assistants
|
| 13 |
+
|
| 14 |
+
This project demonstrates a powerful data analysis agent built using the official **OpenAI Assistants API**. The agent leverages the built-in **Code Interpreter** tool to analyze user-uploaded CSV files, answer questions, and generate visualizations.
|
| 15 |
+
|
| 16 |
+
The web interface is created with Gradio, and the project environment is managed by `uv`.
|
| 17 |
+
|
| 18 |
+
## π How to Use the Live Demo
|
| 19 |
+
|
| 20 |
+
1. **Upload a CSV File:** Use the file uploader to select a `.csv` file from your computer.
|
| 21 |
+
2. **Ask a Question:** In the textbox, ask a question about your data in plain English. For example:
|
| 22 |
+
* "What is the average age in the dataset?"
|
| 23 |
+
* "Create a pie chart showing the distribution of categories."
|
| 24 |
+
* "What are the key insights from this data? Provide one recommendation."
|
| 25 |
+
3. **Run Analysis:** Click the "Run Analysis" button. The agent will process your file and question on OpenAI's servers and return a detailed text answer along with any generated plots.
|
| 26 |
+
|
| 27 |
+
---
|
| 28 |
+
|
| 29 |
+
## π οΈ Local Setup and Execution (For Developers)
|
| 30 |
+
|
| 31 |
+
Follow these steps to run the application on your own machine.
|
| 32 |
+
|
| 33 |
+
### 1. Clone the Repository
|
| 34 |
+
|
| 35 |
+
```bash
|
| 36 |
+
git clone [https://github.com/Shiverion/Data-analysis-using-OpenAI-Assistant.git](https://github.com/Shiverion/Data-analysis-using-OpenAI-Assistant.git)
|
| 37 |
+
cd your-repo-name
|
| 38 |
+
```
|
| 39 |
+
2. Set Up the Environment with uv
|
| 40 |
+
This project uses uv for fast and reproducible environment management.
|
| 41 |
+
|
| 42 |
+
First, install uv if you haven't already:
|
| 43 |
+
|
| 44 |
+
# On macOS / Linux
|
| 45 |
+
```bash
|
| 46 |
+
curl -LsSf [https://astral.sh/uv/install.sh](https://astral.sh/uv/install.sh) | sh
|
| 47 |
+
```
|
| 48 |
+
|
| 49 |
+
# On Windows
|
| 50 |
+
``` bash
|
| 51 |
+
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
Then, sync the environment. This command creates a virtual environment and installs the exact package versions from the uv.lock file.
|
| 55 |
+
|
| 56 |
+
```bash
|
| 57 |
+
uv sync
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
### 3. Set Up Your API Key
|
| 61 |
+
Create a file named `.env` in the root of the project and add your OpenAI API key to it:
|
| 62 |
+
OPENAI_API_KEY='your-secret-key-here'
|
| 63 |
+
|
| 64 |
+
### 4. Run the Application
|
| 65 |
+
Use `uv` to run the app within the managed environment:
|
| 66 |
+
|
| 67 |
+
``` bash
|
| 68 |
+
uv run app.py
|
| 69 |
+
```
|
| 70 |
+
---
|
| 71 |
+
|
| 72 |
+
Open the local URL (e.g., http://127.0.0.1:7860) in your browser.
|
| 73 |
+
|
| 74 |
+
π File Structure
|
| 75 |
+
- **app.py:** The main Gradio application script containing the agent logic.
|
| 76 |
+
|
| 77 |
+
- **requirements.txt:** A list of Python dependencies for Hugging Face Spaces.
|
| 78 |
+
|
| 79 |
+
- **uv.lock:** A definitive lockfile for reproducible environments with uv.
|
| 80 |
+
|
| 81 |
+
- **.env:** Local file for storing your secret API key (ignored by Git).
|
| 82 |
+
|
| 83 |
+
- **.gitignore:** Specifies files for Git to ignore.
|