|
import gradio as gr |
|
import pandas as pd |
|
import matplotlib.pyplot as plt |
|
import io |
|
import google.generativeai as genai |
|
from PIL import Image |
|
|
|
def process_file(api_key, file, instructions): |
|
|
|
genai.configure(api_key=api_key) |
|
model = genai.GenerativeModel('gemini-2.5-pro-latest') |
|
|
|
|
|
try: |
|
if file.name.endswith('.csv'): |
|
df = pd.read_csv(file.name) |
|
else: |
|
df = pd.read_excel(file.name) |
|
except Exception as e: |
|
return [f"File Error: {str(e)}"] * 3 |
|
|
|
|
|
prompt = f"""Generate exactly 3 distinct matplotlib visualizations for: |
|
Columns: {list(df.columns)} |
|
Data types: {dict(df.dtypes)} |
|
Sample data: {df.head(3).to_dict()} |
|
|
|
Requirements: |
|
1. 1920x1080 resolution (figsize=(16,9), dpi=120) |
|
2. Professional styling (seaborn, grid, proper labels) |
|
3. Diverse chart types (include at least 1 advanced visualization) |
|
|
|
User instructions: {instructions or 'None provided |