eagle0504 commited on
Commit
485ef95
·
verified ·
1 Parent(s): e02eeee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -35
app.py CHANGED
@@ -73,6 +73,7 @@ if clear_button:
73
  counter_placeholder.write(f"Next item ...")
74
 
75
  # Insert a file uploader that accepts multiple files at a time
 
76
  if uploaded_file is not None:
77
  # Success message
78
  st.sidebar.success("File uploaded successfully.")
@@ -80,41 +81,45 @@ if uploaded_file is not None:
80
  # Can be used wherever a "file-like" object is accepted:
81
  df = pd.read_csv(uploaded_file)
82
 
83
- # Generate the HTML using Pygwalker
84
- pyg_html = pyg.walk(df, return_html=True)
85
-
86
- # Embed the HTML into the Streamlit app
87
- components.html(pyg_html, height=1000, scrolling=True)
88
-
89
- # Instantiate a LLM
90
- OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
91
- llm = OpenAI(api_token=OPENAI_API_KEY)
92
- pandas_ai = PandasAI(llm)
93
-
94
- # Container for chat history
95
- response_container = st.container()
96
- container = st.container()
97
- with container:
98
- with st.form(key="my_form", clear_on_submit=True):
99
- user_input = st.text_area(
100
- "Enter your question here:", key="input", height=100
101
- )
102
- submit_button = st.form_submit_button(label="Send")
103
-
104
- if submit_button:
105
- output = pandas_ai(df, prompt=user_input)
106
- st.session_state["past"].append(user_input)
107
- st.session_state["generated"].append(
108
- {"type": "normal", "data": f"{output}"}
109
- )
110
-
111
- if st.session_state["generated"]:
112
- with response_container:
113
- for i in range(len(st.session_state["generated"])):
114
- message(st.session_state["past"][i], is_user=True, key=str(i) + "_user")
115
- answer = st.session_state["generated"][i]["data"]
116
- message(answer)
117
- counter_placeholder.write(f"All rights reserved @ Yiqiao Yin")
 
 
 
 
118
 
119
  else:
120
  st.warning("Please upload a csv file.")
 
73
  counter_placeholder.write(f"Next item ...")
74
 
75
  # Insert a file uploader that accepts multiple files at a time
76
+ col1, col2 = st.columns([3, 1])
77
  if uploaded_file is not None:
78
  # Success message
79
  st.sidebar.success("File uploaded successfully.")
 
81
  # Can be used wherever a "file-like" object is accepted:
82
  df = pd.read_csv(uploaded_file)
83
 
84
+ # Col 1:
85
+ with col1:
86
+ # Generate the HTML using Pygwalker
87
+ pyg_html = pyg.walk(df, return_html=True)
88
+
89
+ # Embed the HTML into the Streamlit app
90
+ components.html(pyg_html, height=1000, scrolling=True)
91
+
92
+ # Col 2:
93
+ with col2:
94
+ # Instantiate a LLM
95
+ OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
96
+ llm = OpenAI(api_token=OPENAI_API_KEY)
97
+ pandas_ai = PandasAI(llm)
98
+
99
+ # Container for chat history
100
+ response_container = st.container()
101
+ container = st.container()
102
+ with container:
103
+ with st.form(key="my_form", clear_on_submit=True):
104
+ user_input = st.text_area(
105
+ "Enter your question here:", key="input", height=100
106
+ )
107
+ submit_button = st.form_submit_button(label="Send")
108
+
109
+ if submit_button:
110
+ output = pandas_ai(df, prompt=user_input)
111
+ st.session_state["past"].append(user_input)
112
+ st.session_state["generated"].append(
113
+ {"type": "normal", "data": f"{output}"}
114
+ )
115
+
116
+ if st.session_state["generated"]:
117
+ with response_container:
118
+ for i in range(len(st.session_state["generated"])):
119
+ message(st.session_state["past"][i], is_user=True, key=str(i) + "_user")
120
+ answer = st.session_state["generated"][i]["data"]
121
+ message(answer)
122
+ counter_placeholder.write(f"All rights reserved @ Yiqiao Yin")
123
 
124
  else:
125
  st.warning("Please upload a csv file.")