DrishtiSharma commited on
Commit
592efed
Β·
verified Β·
1 Parent(s): c765b68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -50,6 +50,8 @@ elif model_choice == "GPT-4o":
50
  # Initialize session state for data persistence
51
  if "df" not in st.session_state:
52
  st.session_state.df = None
 
 
53
 
54
  # Dataset Input
55
  input_option = st.radio("Select Dataset Input:", ["Use Hugging Face Dataset", "Upload CSV File"])
@@ -61,6 +63,7 @@ if input_option == "Use Hugging Face Dataset":
61
  with st.spinner("Loading dataset..."):
62
  dataset = load_dataset(dataset_name, split="train")
63
  st.session_state.df = pd.DataFrame(dataset)
 
64
  st.success(f"Dataset '{dataset_name}' loaded successfully!")
65
  except Exception as e:
66
  st.error(f"Error: {e}")
@@ -70,16 +73,16 @@ elif input_option == "Upload CSV File":
70
  if uploaded_file:
71
  try:
72
  st.session_state.df = pd.read_csv(uploaded_file)
 
73
  st.success("File uploaded successfully!")
74
  except Exception as e:
75
  st.error(f"Error loading file: {e}")
76
 
77
- # Display Dataset Preview
78
- if st.session_state.df is not None:
79
  st.subheader("πŸ“‚ Dataset Preview")
80
  st.dataframe(st.session_state.df.head())
81
 
82
-
83
  # SQL-RAG Analysis
84
  if st.session_state.df is not None:
85
  temp_dir = tempfile.TemporaryDirectory()
 
50
  # Initialize session state for data persistence
51
  if "df" not in st.session_state:
52
  st.session_state.df = None
53
+ if "show_preview" not in st.session_state:
54
+ st.session_state.show_preview = False
55
 
56
  # Dataset Input
57
  input_option = st.radio("Select Dataset Input:", ["Use Hugging Face Dataset", "Upload CSV File"])
 
63
  with st.spinner("Loading dataset..."):
64
  dataset = load_dataset(dataset_name, split="train")
65
  st.session_state.df = pd.DataFrame(dataset)
66
+ st.session_state.show_preview = True # Show preview after loading
67
  st.success(f"Dataset '{dataset_name}' loaded successfully!")
68
  except Exception as e:
69
  st.error(f"Error: {e}")
 
73
  if uploaded_file:
74
  try:
75
  st.session_state.df = pd.read_csv(uploaded_file)
76
+ st.session_state.show_preview = True # Show preview after loading
77
  st.success("File uploaded successfully!")
78
  except Exception as e:
79
  st.error(f"Error loading file: {e}")
80
 
81
+ # Show Dataset Preview Only After Loading
82
+ if st.session_state.df is not None and st.session_state.show_preview:
83
  st.subheader("πŸ“‚ Dataset Preview")
84
  st.dataframe(st.session_state.df.head())
85
 
 
86
  # SQL-RAG Analysis
87
  if st.session_state.df is not None:
88
  temp_dir = tempfile.TemporaryDirectory()