bluenevus commited on
Commit
69a028d
Β·
verified Β·
1 Parent(s): 3e28fd8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -6,27 +6,28 @@ import google.generativeai as genai
6
  from PIL import Image
7
 
8
  def process_file(api_key, file, instructions):
9
- # ... [keep the existing process_file function identical] ...
 
 
10
 
11
- # Fixed Gradio interface with compatible theme settings
12
- with gr.Blocks(theme=gr.themes.Default(spacing_size="lg")) as demo: # Changed from "xl" to "lg"
13
- gr.Markdown("# **HD Data Visualizer** πŸ“Šβœ¨")
14
-
15
- with gr.Row():
16
- api_key = gr.Textbox(label="πŸ”‘ Gemini API Key", type="password")
17
- file = gr.File(label="πŸ“ Upload Dataset", file_types=[".csv", ".xlsx"])
 
 
 
 
 
 
 
18
 
19
- instructions = gr.Textbox(label="πŸ’‘ Custom Instructions (optional)",
20
- placeholder="E.g.: Focus on time series patterns...")
21
- submit = gr.Button("πŸš€ Generate Visualizations", variant="primary")
 
22
 
23
- with gr.Row():
24
- outputs = [gr.Image(label=f"Visualization {i+1}", width=600) for i in range(3)]
25
-
26
- submit.click(
27
- process_file,
28
- inputs=[api_key, file, instructions],
29
- outputs=outputs
30
- )
31
-
32
- demo.launch()
 
6
  from PIL import Image
7
 
8
  def process_file(api_key, file, instructions):
9
+ # Configure Gemini API
10
+ genai.configure(api_key=api_key)
11
+ model = genai.GenerativeModel('gemini-2.5-pro-latest')
12
 
13
+ # File handling with error prevention
14
+ try:
15
+ if file.name.endswith('.csv'):
16
+ df = pd.read_csv(file.name)
17
+ else:
18
+ df = pd.read_excel(file.name)
19
+ except Exception as e:
20
+ return [f"File Error: {str(e)}"] * 3
21
+
22
+ # Enhanced prompt template
23
+ prompt = f"""Generate exactly 3 distinct matplotlib visualizations for:
24
+ Columns: {list(df.columns)}
25
+ Data types: {dict(df.dtypes)}
26
+ Sample data: {df.head(3).to_dict()}
27
 
28
+ Requirements:
29
+ 1. 1920x1080 resolution (figsize=(16,9), dpi=120)
30
+ 2. Professional styling (seaborn, grid, proper labels)
31
+ 3. Diverse chart types (include at least 1 advanced visualization)
32
 
33
+ User instructions: {instructions or 'None provided