Update lab/interim.py
Browse files- lab/interim.py +34 -15
lab/interim.py
CHANGED
@@ -8,6 +8,7 @@ import matplotlib.pyplot as plt
|
|
8 |
from datasets import load_dataset
|
9 |
from langchain_groq import ChatGroq
|
10 |
from langchain_openai import ChatOpenAI
|
|
|
11 |
|
12 |
# Load environment variables
|
13 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
@@ -32,21 +33,39 @@ def initialize_llm(model_choice):
|
|
32 |
model_choice = st.radio("Select LLM", ["GPT-4o", "llama-3.3-70b"], index=0, horizontal=True)
|
33 |
llm = initialize_llm(model_choice)
|
34 |
|
35 |
-
#
|
36 |
-
@st.cache_data
|
37 |
-
def load_repo_dataset(file_path):
|
38 |
-
return pd.read_csv(file_path)
|
39 |
-
|
40 |
-
@st.cache_data
|
41 |
def load_huggingface_dataset(dataset_name):
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
-
@st.cache_data
|
48 |
def load_uploaded_csv(uploaded_file):
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
# Dataset selection logic
|
52 |
def load_dataset_into_session():
|
@@ -60,7 +79,8 @@ def load_dataset_into_session():
|
|
60 |
file_path = "./source/test.csv"
|
61 |
if st.button("Load Dataset"):
|
62 |
try:
|
63 |
-
st.
|
|
|
64 |
st.success(f"File loaded successfully from '{file_path}'!")
|
65 |
except Exception as e:
|
66 |
st.error(f"Error loading dataset from the repo directory: {e}")
|
@@ -155,10 +175,9 @@ with st.sidebar:
|
|
155 |
" - Example: 'Predict if the patent will be accepted.'\n"
|
156 |
" - Example: 'What is the primary classification of this patent?'\n"
|
157 |
" - Example: 'Summarize the abstract of this patent.'\n"
|
158 |
-
#"4. Download the processed dataset as a CSV file."
|
159 |
)
|
160 |
st.markdown("---")
|
161 |
st.header("References:")
|
162 |
st.markdown(
|
163 |
"1. [Chat With Your CSV File With PandasAI - Prince Krampah](https://medium.com/aimonks/chat-with-your-csv-file-with-pandasai-22232a13c7b7)"
|
164 |
-
)
|
|
|
8 |
from datasets import load_dataset
|
9 |
from langchain_groq import ChatGroq
|
10 |
from langchain_openai import ChatOpenAI
|
11 |
+
import time
|
12 |
|
13 |
# Load environment variables
|
14 |
openai_api_key = os.getenv("OPENAI_API_KEY")
|
|
|
33 |
model_choice = st.radio("Select LLM", ["GPT-4o", "llama-3.3-70b"], index=0, horizontal=True)
|
34 |
llm = initialize_llm(model_choice)
|
35 |
|
36 |
+
# Dataset loading without caching to support progress bar
|
|
|
|
|
|
|
|
|
|
|
37 |
def load_huggingface_dataset(dataset_name):
|
38 |
+
# Initialize progress bar
|
39 |
+
progress_bar = st.progress(0)
|
40 |
+
try:
|
41 |
+
# Incrementally update progress
|
42 |
+
progress_bar.progress(10)
|
43 |
+
dataset = load_dataset(dataset_name, name="sample", split="train", trust_remote_code=True, uniform_split=True)
|
44 |
+
progress_bar.progress(50)
|
45 |
+
if hasattr(dataset, "to_pandas"):
|
46 |
+
df = dataset.to_pandas()
|
47 |
+
else:
|
48 |
+
df = pd.DataFrame(dataset)
|
49 |
+
progress_bar.progress(100) # Final update to 100%
|
50 |
+
return df
|
51 |
+
except Exception as e:
|
52 |
+
progress_bar.progress(0) # Reset progress bar on failure
|
53 |
+
raise e
|
54 |
|
|
|
55 |
def load_uploaded_csv(uploaded_file):
|
56 |
+
# Initialize progress bar
|
57 |
+
progress_bar = st.progress(0)
|
58 |
+
try:
|
59 |
+
# Simulate progress
|
60 |
+
progress_bar.progress(10)
|
61 |
+
time.sleep(1) # Simulate file processing delay
|
62 |
+
progress_bar.progress(50)
|
63 |
+
df = pd.read_csv(uploaded_file)
|
64 |
+
progress_bar.progress(100) # Final update
|
65 |
+
return df
|
66 |
+
except Exception as e:
|
67 |
+
progress_bar.progress(0) # Reset progress bar on failure
|
68 |
+
raise e
|
69 |
|
70 |
# Dataset selection logic
|
71 |
def load_dataset_into_session():
|
|
|
79 |
file_path = "./source/test.csv"
|
80 |
if st.button("Load Dataset"):
|
81 |
try:
|
82 |
+
with st.spinner("Loading dataset from the repo directory..."):
|
83 |
+
st.session_state.df = pd.read_csv(file_path)
|
84 |
st.success(f"File loaded successfully from '{file_path}'!")
|
85 |
except Exception as e:
|
86 |
st.error(f"Error loading dataset from the repo directory: {e}")
|
|
|
175 |
" - Example: 'Predict if the patent will be accepted.'\n"
|
176 |
" - Example: 'What is the primary classification of this patent?'\n"
|
177 |
" - Example: 'Summarize the abstract of this patent.'\n"
|
|
|
178 |
)
|
179 |
st.markdown("---")
|
180 |
st.header("References:")
|
181 |
st.markdown(
|
182 |
"1. [Chat With Your CSV File With PandasAI - Prince Krampah](https://medium.com/aimonks/chat-with-your-csv-file-with-pandasai-22232a13c7b7)"
|
183 |
+
)
|