MCPcopy Create free account
hub / github.com/CloudOrc/SolidUI / execute_code

Function execute_code

solidui/spaces_plugin/app.py:41–55  ·  view source on GitHub ↗
(code)

Source from the content-addressed store, hash-verified

39
40# Execute Python code and generate images
41def execute_code(code):
42 namespace = {}
43 exec(code, namespace)
44 fig = namespace.get('fig') # Assume the code generates a matplotlib figure named 'fig'
45 if fig:
46 img = get_image_data(fig)
47
48 img_byte_arr = io.BytesIO()
49 img.save(img_byte_arr, format='PNG')
50 img_byte_arr = img_byte_arr.getvalue()
51 img_b64 = base64.b64encode(img_byte_arr).decode('utf-8')
52
53 return img_b64
54 else:
55 raise ValueError("The code did not generate a matplotlib figure named 'fig'")
56
57
58def gpt_inference(base_url, model, openai_key, prompt):

Callers 1

gpt_inferenceFunction · 0.85

Calls 2

get_image_dataFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected