Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import io
|
|
5 |
import ast
|
6 |
from PIL import Image, ImageDraw
|
7 |
import google.generativeai as genai
|
|
|
8 |
|
9 |
def process_file(api_key, file, instructions):
|
10 |
try:
|
@@ -27,6 +28,11 @@ def process_file(api_key, file, instructions):
|
|
27 |
|
28 |
# Extract code block safely
|
29 |
code_block = response.text.split('```python')[1].split('```')[0].strip()
|
|
|
|
|
|
|
|
|
|
|
30 |
plots = ast.literal_eval(code_block)
|
31 |
|
32 |
# Generate visualizations
|
@@ -59,9 +65,11 @@ def process_file(api_key, file, instructions):
|
|
59 |
return images if len(images) == 3 else images + [Image.new('RGB', (800, 600), (255,255,255))]*(3-len(images))
|
60 |
|
61 |
except Exception as e:
|
62 |
-
|
|
|
|
|
63 |
draw = ImageDraw.Draw(error_image)
|
64 |
-
draw.text((10,
|
65 |
return [error_image] * 3
|
66 |
|
67 |
with gr.Blocks(theme=gr.themes.Default(spacing_size="lg")) as demo:
|
|
|
5 |
import ast
|
6 |
from PIL import Image, ImageDraw
|
7 |
import google.generativeai as genai
|
8 |
+
import traceback
|
9 |
|
10 |
def process_file(api_key, file, instructions):
|
11 |
try:
|
|
|
28 |
|
29 |
# Extract code block safely
|
30 |
code_block = response.text.split('```python')[1].split('```')[0].strip()
|
31 |
+
|
32 |
+
# Print the code block for debugging
|
33 |
+
print("Generated code block:")
|
34 |
+
print(code_block)
|
35 |
+
|
36 |
plots = ast.literal_eval(code_block)
|
37 |
|
38 |
# Generate visualizations
|
|
|
65 |
return images if len(images) == 3 else images + [Image.new('RGB', (800, 600), (255,255,255))]*(3-len(images))
|
66 |
|
67 |
except Exception as e:
|
68 |
+
error_message = f"Error: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
|
69 |
+
print(error_message) # Print to console for debugging
|
70 |
+
error_image = Image.new('RGB', (800, 400), (255, 255, 255))
|
71 |
draw = ImageDraw.Draw(error_image)
|
72 |
+
draw.text((10, 10), error_message, fill=(255, 0, 0))
|
73 |
return [error_image] * 3
|
74 |
|
75 |
with gr.Blocks(theme=gr.themes.Default(spacing_size="lg")) as demo:
|