Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,10 @@ import base64
|
|
12 |
# Load environment variables
|
13 |
load_dotenv()
|
14 |
|
15 |
-
|
|
|
|
|
|
|
16 |
"""
|
17 |
Process the uploaded CSV file with the given query using PandasAI
|
18 |
"""
|
@@ -23,9 +26,6 @@ def process_data(file, query, api_key):
|
|
23 |
|
24 |
if not query.strip():
|
25 |
return "Please enter a query.", None
|
26 |
-
|
27 |
-
if not api_key.strip():
|
28 |
-
return "Please enter your Groq API key.", None
|
29 |
|
30 |
# Read the CSV file
|
31 |
df_data = pd.read_csv(file.name)
|
@@ -33,7 +33,7 @@ def process_data(file, query, api_key):
|
|
33 |
# Initialize Groq LLM
|
34 |
llm = ChatGroq(
|
35 |
model_name="mixtral-8x7b-32768", # Using a more stable model
|
36 |
-
api_key=
|
37 |
temperature=0
|
38 |
)
|
39 |
|
@@ -90,22 +90,15 @@ def create_interface():
|
|
90 |
Upload a CSV file and ask questions about your data. The AI will analyze and visualize your data accordingly.
|
91 |
|
92 |
**Instructions:**
|
93 |
-
1.
|
94 |
-
2.
|
95 |
-
3.
|
96 |
-
4. Click Submit to get results
|
97 |
"""
|
98 |
)
|
99 |
|
100 |
with gr.Row():
|
101 |
with gr.Column(scale=1):
|
102 |
# Input components
|
103 |
-
api_key_input = gr.Textbox(
|
104 |
-
label="Groq API Key (get from console.groq.com/keys)",
|
105 |
-
placeholder="Enter your Groq API key here...",
|
106 |
-
type="password"
|
107 |
-
)
|
108 |
-
|
109 |
file_input = gr.File(
|
110 |
label="Upload CSV File",
|
111 |
file_types=[".csv"]
|
@@ -147,17 +140,15 @@ def create_interface():
|
|
147 |
# Event handlers
|
148 |
submit_btn.click(
|
149 |
fn=process_data,
|
150 |
-
inputs=[file_input, query_input
|
151 |
-
outputs=[result_output, chart_output]
|
152 |
-
show_progress=True
|
153 |
)
|
154 |
|
155 |
# Allow Enter key to submit
|
156 |
query_input.submit(
|
157 |
fn=process_data,
|
158 |
-
inputs=[file_input, query_input
|
159 |
-
outputs=[result_output, chart_output]
|
160 |
-
show_progress=True
|
161 |
)
|
162 |
|
163 |
return demo
|
|
|
12 |
# Load environment variables
|
13 |
load_dotenv()
|
14 |
|
15 |
+
# Hardcoded API key - Replace with your actual Groq API key
|
16 |
+
GROQ_API_KEY = "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"
|
17 |
+
|
18 |
+
def process_data(file, query):
|
19 |
"""
|
20 |
Process the uploaded CSV file with the given query using PandasAI
|
21 |
"""
|
|
|
26 |
|
27 |
if not query.strip():
|
28 |
return "Please enter a query.", None
|
|
|
|
|
|
|
29 |
|
30 |
# Read the CSV file
|
31 |
df_data = pd.read_csv(file.name)
|
|
|
33 |
# Initialize Groq LLM
|
34 |
llm = ChatGroq(
|
35 |
model_name="mixtral-8x7b-32768", # Using a more stable model
|
36 |
+
api_key=GROQ_API_KEY,
|
37 |
temperature=0
|
38 |
)
|
39 |
|
|
|
90 |
Upload a CSV file and ask questions about your data. The AI will analyze and visualize your data accordingly.
|
91 |
|
92 |
**Instructions:**
|
93 |
+
1. Upload your CSV file
|
94 |
+
2. Enter your query (e.g., "Show top 5 countries by population", "Create a bar plot of sales by region")
|
95 |
+
3. Click Submit to get results
|
|
|
96 |
"""
|
97 |
)
|
98 |
|
99 |
with gr.Row():
|
100 |
with gr.Column(scale=1):
|
101 |
# Input components
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
file_input = gr.File(
|
103 |
label="Upload CSV File",
|
104 |
file_types=[".csv"]
|
|
|
140 |
# Event handlers
|
141 |
submit_btn.click(
|
142 |
fn=process_data,
|
143 |
+
inputs=[file_input, query_input],
|
144 |
+
outputs=[result_output, chart_output]
|
|
|
145 |
)
|
146 |
|
147 |
# Allow Enter key to submit
|
148 |
query_input.submit(
|
149 |
fn=process_data,
|
150 |
+
inputs=[file_input, query_input],
|
151 |
+
outputs=[result_output, chart_output]
|
|
|
152 |
)
|
153 |
|
154 |
return demo
|