Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.")
|