Spaces:
Build error
Build error
upgrade all
Browse files
app.py
CHANGED
|
@@ -8,6 +8,13 @@ load_dotenv()
|
|
| 8 |
import matplotlib.pyplot as plt
|
| 9 |
import streamlit as st
|
| 10 |
from pytrie import SortedStringTrie
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
## Configure Genai Key
|
| 12 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 13 |
|
|
@@ -68,6 +75,8 @@ if uploaded_file is not None:
|
|
| 68 |
# all columns append in list
|
| 69 |
column_names = df.columns.tolist()
|
| 70 |
column = ', '.join(column_names)
|
|
|
|
|
|
|
| 71 |
# buid auto complete data structure
|
| 72 |
suggestion_tool.build_from_corpus(auto_complete_corpus)
|
| 73 |
# show the dataframe columns
|
|
@@ -111,15 +120,16 @@ if submit1:
|
|
| 111 |
now your task is to generate pandas code from given dataframe based on english questions without any variable name.
|
| 112 |
The given pandas DataFrame name is df and the columns are {column},
|
| 113 |
now generate pandas code from the df dataframe based on englsih question
|
|
|
|
| 114 |
|
| 115 |
For example :
|
| 116 |
For example 1 :
|
| 117 |
english query : how many rows ?
|
| 118 |
-
python code : len(df.index)
|
| 119 |
|
| 120 |
For example 2 :
|
| 121 |
english query : how many columns ?
|
| 122 |
-
python code : len(df.columns)
|
| 123 |
"""
|
| 124 |
# get response from model
|
| 125 |
response=get_gemini_response(question1,prompt1)
|
|
@@ -130,15 +140,21 @@ if submit1:
|
|
| 130 |
# st.text(response)
|
| 131 |
st.set_option('deprecation.showPyplotGlobalUse', False)
|
| 132 |
# show the plot on the user side
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
if submit2:
|
| 138 |
prompt2 = f"""
|
| 139 |
You are an expert in generating python code for statistical chart like bar, pie, histogram, scatter from a pandas dataframe.
|
| 140 |
now your task is to generate python code for statistical chart from given dataframe based on english questions.
|
| 141 |
-
The given pandas DataFrame name is df and the columns are {column}
|
| 142 |
now generate Python code from the df dataframe based on englsih question
|
| 143 |
|
| 144 |
For example :
|
|
|
|
| 8 |
import matplotlib.pyplot as plt
|
| 9 |
import streamlit as st
|
| 10 |
from pytrie import SortedStringTrie
|
| 11 |
+
import sys
|
| 12 |
+
from io import StringIO
|
| 13 |
+
|
| 14 |
+
output_stream = StringIO()
|
| 15 |
+
sys.stdout = output_stream
|
| 16 |
+
|
| 17 |
+
|
| 18 |
## Configure Genai Key
|
| 19 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
| 20 |
|
|
|
|
| 75 |
# all columns append in list
|
| 76 |
column_names = df.columns.tolist()
|
| 77 |
column = ', '.join(column_names)
|
| 78 |
+
columns_and_types = dict(zip(df.columns, df.dtypes))
|
| 79 |
+
columns_and_types = ', '.join(columns_and_types)
|
| 80 |
# buid auto complete data structure
|
| 81 |
suggestion_tool.build_from_corpus(auto_complete_corpus)
|
| 82 |
# show the dataframe columns
|
|
|
|
| 120 |
now your task is to generate pandas code from given dataframe based on english questions without any variable name.
|
| 121 |
The given pandas DataFrame name is df and the columns are {column},
|
| 122 |
now generate pandas code from the df dataframe based on englsih question
|
| 123 |
+
please add print all the time
|
| 124 |
|
| 125 |
For example :
|
| 126 |
For example 1 :
|
| 127 |
english query : how many rows ?
|
| 128 |
+
python code : print(len(df.index))
|
| 129 |
|
| 130 |
For example 2 :
|
| 131 |
english query : how many columns ?
|
| 132 |
+
python code : print(len(df.columns))
|
| 133 |
"""
|
| 134 |
# get response from model
|
| 135 |
response=get_gemini_response(question1,prompt1)
|
|
|
|
| 140 |
# st.text(response)
|
| 141 |
st.set_option('deprecation.showPyplotGlobalUse', False)
|
| 142 |
# show the plot on the user side
|
| 143 |
+
try:
|
| 144 |
+
exec(response, globals(), locals())
|
| 145 |
+
result = output_stream.getvalue()
|
| 146 |
+
st.write(result)
|
| 147 |
+
except Exception as e:
|
| 148 |
+
st.write("Error:", e)
|
| 149 |
+
finally:
|
| 150 |
+
# Reset sys.stdout to its original value
|
| 151 |
+
sys.stdout = sys.__stdout__
|
| 152 |
|
| 153 |
if submit2:
|
| 154 |
prompt2 = f"""
|
| 155 |
You are an expert in generating python code for statistical chart like bar, pie, histogram, scatter from a pandas dataframe.
|
| 156 |
now your task is to generate python code for statistical chart from given dataframe based on english questions.
|
| 157 |
+
The given pandas DataFrame name is df and the columns are {column} and columns data types are {columns_and_types}
|
| 158 |
now generate Python code from the df dataframe based on englsih question
|
| 159 |
|
| 160 |
For example :
|