|
import gradio as gr |
|
import pandas as pd |
|
import matplotlib.pyplot as plt |
|
import io |
|
import google.generativeai as genai |
|
from PIL import Image, ImageDraw, ImageFont |
|
import ast |
|
import re |
|
import traceback |
|
|
|
def process_file(api_key, file, instructions): |
|
|
|
pass |
|
|
|
def sanitize_code(code_block, columns): |
|
|
|
pass |
|
|
|
def execute_plot_code(code, df): |
|
|
|
pass |
|
|
|
def generate_error_image(message): |
|
"""Create error indication image with message""" |
|
try: |
|
img = Image.new('RGB', (1920, 1080), color=(255, 255, 255)) |
|
draw = ImageDraw.Draw(img) |
|
|
|
|
|
font = ImageFont.load_default() |
|
|
|
|
|
text_width, text_height = draw.textsize(message, font=font) |
|
x = (1920 - text_width) / 2 |
|
y = (1080 - text_height) / 2 |
|
|
|
|
|
draw.text((x, y), message, font=font, fill=(255, 0, 0)) |
|
|
|
return img |
|
except Exception as e: |
|
|
|
return Image.new('RGB', (1920, 1080), color=(255, 255, 255)) |
|
|
|
|
|
with gr.Blocks(theme=gr.themes.Default(spacing_size="lg")) as demo: |
|
gr.Markdown("# Professional Data Visualizer") |
|
|
|
with gr.Row(): |
|
api_key = gr.Textbox(label="Gemini API Key", type="password") |
|
file = gr.File(label="Upload Data File", file_types=[".csv", ".xlsx"]) |
|
|
|
instructions = gr.Textbox(label="Visualization Instructions") |
|
submit = gr.Button("Generate Insights", variant="primary") |
|
|
|
with gr.Row(): |
|
outputs = [gr.Image(label=f"Visualization {i+1}", width=600) for i in range(3)] |
|
|
|
submit.click( |
|
process_file, |
|
inputs=[api_key, file, instructions], |
|
outputs=outputs |
|
) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |