Spaces:
Build error
Build error
phillip1029 commited on
Commit ·
a60f3b5
1
Parent(s): 76e9f62
conversational data science
Browse files- README.md +11 -13
- requirements.txt +4 -0
- streamlit_app.py +68 -0
README.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
# Conversational Data Science
|
| 2 |
+
|
| 3 |
+
## Overview
|
| 4 |
+
This repository showcases a demonstrative project on how generative AI is transforming the field of data science. By leveraging the capabilities of PandasAI and Streamlit, this project provides an interactive example of Conversational Data Science, emphasizing the synergy between AI and traditional data analysis.
|
| 5 |
+
|
| 6 |
+
## Key Features
|
| 7 |
+
- **PandasAI Integration:** Utilizing the powerful features of PandasAI for AI-driven data analysis.
|
| 8 |
+
- **Streamlit Application:** An interactive web application built with Streamlit to demonstrate real-time data science tasks in a conversational manner.
|
| 9 |
+
- **Generative AI Examples:** Examples and use-cases showing how generative AI models can enhance data science workflows.
|
| 10 |
+
|
| 11 |
+
|
|
|
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas
|
| 2 |
+
pandasai
|
| 3 |
+
streamlit
|
| 4 |
+
python-dotenv
|
streamlit_app.py
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from pandasai import SmartDataframe
|
| 4 |
+
from pandasai.llm import OpenAI
|
| 5 |
+
import pandas as pd
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
# load the .env file
|
| 9 |
+
from dotenv import load_dotenv
|
| 10 |
+
load_dotenv()
|
| 11 |
+
|
| 12 |
+
API_KEY =os.getenv("OPENAI_API_KEY")
|
| 13 |
+
|
| 14 |
+
llm = OpenAI(api_token=API_KEY, model="gpt-4-1106-preview")
|
| 15 |
+
|
| 16 |
+
st.title("Conversational Data Science")
|
| 17 |
+
|
| 18 |
+
st.sidebar.write("Select a dataset to load:")
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
if "sdf" not in st.session_state:
|
| 22 |
+
st.session_state.sdf = None
|
| 23 |
+
|
| 24 |
+
if "prompt_history" not in st.session_state:
|
| 25 |
+
st.session_state.prompt_history = []
|
| 26 |
+
|
| 27 |
+
uploaded_file = st.sidebar.file_uploader(
|
| 28 |
+
"Choose a CSV file. This should be in long format (one datapoint per row).",
|
| 29 |
+
type="csv",
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
if uploaded_file is not None:
|
| 33 |
+
df = pd.read_csv(uploaded_file)
|
| 34 |
+
sdf = SmartDataframe(df, config={"llm": llm})
|
| 35 |
+
st.session_state.sdf = sdf
|
| 36 |
+
|
| 37 |
+
def get_text():
|
| 38 |
+
input_text = st.text_input("You: ","Would you please give me a summary of the data?", key="input")
|
| 39 |
+
return input_text
|
| 40 |
+
|
| 41 |
+
def generate_answer(question):
|
| 42 |
+
return sdf.chat(question)
|
| 43 |
+
|
| 44 |
+
if "conversation" not in st.session_state:
|
| 45 |
+
st.session_state.conversation = []
|
| 46 |
+
|
| 47 |
+
with st.form(key='my_form'):
|
| 48 |
+
user_input = st.text_input("You: ")
|
| 49 |
+
submit_button = st.form_submit_button(label='Enter')
|
| 50 |
+
|
| 51 |
+
import matplotlib.pyplot as plt
|
| 52 |
+
|
| 53 |
+
if submit_button and user_input:
|
| 54 |
+
response = generate_answer(user_input)
|
| 55 |
+
st.session_state.conversation.append(("You: ", user_input))
|
| 56 |
+
|
| 57 |
+
# If the response is a matplotlib figure, display the chart
|
| 58 |
+
if isinstance(response, plt.Figure):
|
| 59 |
+
st.pyplot(response)
|
| 60 |
+
st.session_state.conversation.append(("AI-Analyst: ", "Here is the chart you requested:"))
|
| 61 |
+
else:
|
| 62 |
+
st.session_state.conversation.append(("AI-Analyst: ", response))
|
| 63 |
+
|
| 64 |
+
for i in range(len(st.session_state.conversation)-1, -1, -2):
|
| 65 |
+
if i-1 >= 0:
|
| 66 |
+
st.markdown(f'<div style="background-color: #f0f0f0; padding: 10px; border-radius: 5px;">{st.session_state.conversation[i-1][0]} {st.session_state.conversation[i-1][1]}</div>', unsafe_allow_html=True)
|
| 67 |
+
if i < len(st.session_state.conversation):
|
| 68 |
+
st.text(f"{st.session_state.conversation[i][0]} {st.session_state.conversation[i][1]}")
|