File size: 2,069 Bytes
4fc79a4 12ce912 23a3b49 12ce912 4fc79a4 12ce912 14c80d9 12ce912 14c80d9 12ce912 23a3b49 14c80d9 12ce912 23a3b49 1ab6fac 23a3b49 1ab6fac 23a3b49 1ab6fac 23a3b49 1ab6fac 23a3b49 5be932a 23a3b49 6cff8d5 23a3b49 6cff8d5 23a3b49 12ce912 23a3b49 6cff8d5 23a3b49 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
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):
# Function implementation goes here
pass # Add proper indentation for actual implementation
def sanitize_code(code_block, columns):
# Function implementation goes here
pass # Add proper indentation for actual implementation
def execute_plot_code(code, df):
# Function implementation goes here
pass # Add proper indentation for actual implementation
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)
# Use default font
font = ImageFont.load_default()
# Calculate text position
text_width, text_height = draw.textsize(message, font=font)
x = (1920 - text_width) / 2
y = (1080 - text_height) / 2
# Draw message
draw.text((x, y), message, font=font, fill=(255, 0, 0))
return img
except Exception as e:
# Fallback if text rendering fails
return Image.new('RGB', (1920, 1080), color=(255, 255, 255))
# Gradio interface
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() |