Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
import base64
|
| 2 |
import io
|
| 3 |
-
import os
|
| 4 |
import ast
|
| 5 |
import traceback
|
| 6 |
from threading import Thread
|
|
@@ -20,6 +19,7 @@ app.layout = dbc.Container([
|
|
| 20 |
html.H1("Data Analysis Dashboard", className="my-4"),
|
| 21 |
dbc.Card([
|
| 22 |
dbc.CardBody([
|
|
|
|
| 23 |
dcc.Upload(
|
| 24 |
id='upload-data',
|
| 25 |
children=html.Div([
|
|
@@ -66,10 +66,9 @@ def parse_contents(contents, filename):
|
|
| 66 |
print(e)
|
| 67 |
return None
|
| 68 |
|
| 69 |
-
def process_data(df, instructions):
|
| 70 |
try:
|
| 71 |
-
# Initialize Gemini
|
| 72 |
-
api_key = os.environ.get('GEMINI_API_KEY')
|
| 73 |
genai.configure(api_key=api_key)
|
| 74 |
model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
|
| 75 |
|
|
@@ -146,17 +145,18 @@ def generate_plot(df, plot_info):
|
|
| 146 |
[Input('submit-button', 'n_clicks')],
|
| 147 |
[State('upload-data', 'contents'),
|
| 148 |
State('upload-data', 'filename'),
|
| 149 |
-
State('instructions', 'value')
|
|
|
|
| 150 |
)
|
| 151 |
-
def update_output(n_clicks, contents, filename, instructions):
|
| 152 |
-
if n_clicks is None or contents is None:
|
| 153 |
return dash.no_update, dash.no_update, dash.no_update
|
| 154 |
|
| 155 |
df = parse_contents(contents, filename)
|
| 156 |
if df is None:
|
| 157 |
return dash.no_update, dash.no_update, dash.no_update
|
| 158 |
|
| 159 |
-
plots = process_data(df, instructions)
|
| 160 |
if plots is None or len(plots) < 3:
|
| 161 |
return dash.no_update, dash.no_update, dash.no_update
|
| 162 |
|
|
|
|
| 1 |
import base64
|
| 2 |
import io
|
|
|
|
| 3 |
import ast
|
| 4 |
import traceback
|
| 5 |
from threading import Thread
|
|
|
|
| 19 |
html.H1("Data Analysis Dashboard", className="my-4"),
|
| 20 |
dbc.Card([
|
| 21 |
dbc.CardBody([
|
| 22 |
+
dbc.Input(id="api-key", placeholder="Enter your Gemini API key", type="password", className="mb-3"),
|
| 23 |
dcc.Upload(
|
| 24 |
id='upload-data',
|
| 25 |
children=html.Div([
|
|
|
|
| 66 |
print(e)
|
| 67 |
return None
|
| 68 |
|
| 69 |
+
def process_data(df, instructions, api_key):
|
| 70 |
try:
|
| 71 |
+
# Initialize Gemini with provided API key
|
|
|
|
| 72 |
genai.configure(api_key=api_key)
|
| 73 |
model = genai.GenerativeModel('gemini-2.5-pro-preview-03-25')
|
| 74 |
|
|
|
|
| 145 |
[Input('submit-button', 'n_clicks')],
|
| 146 |
[State('upload-data', 'contents'),
|
| 147 |
State('upload-data', 'filename'),
|
| 148 |
+
State('instructions', 'value'),
|
| 149 |
+
State('api-key', 'value')]
|
| 150 |
)
|
| 151 |
+
def update_output(n_clicks, contents, filename, instructions, api_key):
|
| 152 |
+
if n_clicks is None or contents is None or not api_key:
|
| 153 |
return dash.no_update, dash.no_update, dash.no_update
|
| 154 |
|
| 155 |
df = parse_contents(contents, filename)
|
| 156 |
if df is None:
|
| 157 |
return dash.no_update, dash.no_update, dash.no_update
|
| 158 |
|
| 159 |
+
plots = process_data(df, instructions, api_key)
|
| 160 |
if plots is None or len(plots) < 3:
|
| 161 |
return dash.no_update, dash.no_update, dash.no_update
|
| 162 |
|