diff --git a/frontend/core/pipelines/pipeline-text-to-app/.DS_Store b/frontend/core/pipelines/pipeline-text-to-app/.DS_Store index d789eeb5..047e3ed2 100644 Binary files a/frontend/core/pipelines/pipeline-text-to-app/.DS_Store and b/frontend/core/pipelines/pipeline-text-to-app/.DS_Store differ diff --git a/frontend/core/pipelines/pipeline-text-to-game/README.md b/frontend/core/pipelines/pipeline-text-to-game/README.md new file mode 100644 index 00000000..3e0410ab --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/README.md @@ -0,0 +1,14 @@ +# text to game app + +Initializes images stored in `Images Block` receives input prompt and returns a fully functional frontend game application. + +### How to use this pipeline + +- Update the `/frontend/core/pipelines/text2game/new-python-i3a2bb98agbh` add the images you would like to have access to during processing, and development. +- Drag and drop the pipeline onto the canvas from the side library. +- Input your desired prompt (Make me a pool game using img_pooltable.png as a backround image) **Note. it is important to append img\_ to the beginning of the png file name** +- Input your API key inside of the password block. +- Press the Run pipeline button. +- The text2game pipeline will produce a view HTML interface that takes you to the app on a web browser, and the Interface maker will take you to a chat iframe interface so you can potentially iterate over the application. + +> Note: In the password blocks, your API key should be under double quotes. diff --git a/frontend/core/pipelines/pipeline-text-to-game/cover-image.png b/frontend/core/pipelines/pipeline-text-to-game/cover-image.png new file mode 100644 index 00000000..da23029b Binary files /dev/null and b/frontend/core/pipelines/pipeline-text-to-game/cover-image.png differ diff --git a/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/Dockerfile b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/Dockerfile new file mode 100644 index 00000000..7f29ac11 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.9 + +WORKDIR /app + +COPY . . + +RUN pip install --no-cache-dir -r requirements.txt diff --git a/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/agents/gpt-4_python_compute/generate/computations.py b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/agents/gpt-4_python_compute/generate/computations.py new file mode 100644 index 00000000..5378303d --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/agents/gpt-4_python_compute/generate/computations.py @@ -0,0 +1,119 @@ +import json +import re +import sys +import traceback + +from langchain.prompts import ChatPromptTemplate +from langchain_openai import ChatOpenAI + +# Define system context +openaiSystemContent = """You are an assistant that generates python code and returns it in a way that must follow the template below. +You absolutely need to give a python code section without abbreviation that follows the template. Do not put code lines at the root, but give only the functions and imports. + +By default, when requested to do change or add to the code, modify the latest code section. But when the user ask to do it on another section, do so. + +In the template, the function compute contains the code and the function test contains a series of call to compute that runs and prints multiple tests. + +Don't insert a __main__ section. + +Template: +import ... + +def compute(in1, in2, in3,...): + '''A textual description of the compute function.''' + + #some code + return {{'out1': out1, 'out2': out2, ...}} + +def test(): + # Call compute multiple times based on a series of inputs. The outputs are then compare with the expected outputs. Print the results and indicate if the tests passed. +""" + + +def extract_python_code(response): + """ + Extracts Python code blocks from a given text, excluding standalone compute() or test() calls. + Assumes that Python code is formatted with triple backticks. + If no Python code blocks are found, returns the whole response. + """ + + # Pattern to match code blocks fenced by triple backticks + pattern_backticks = r"```python\n(.*?)```" + + # Extract code blocks fenced by triple backticks + matches_backticks = re.findall(pattern_backticks, response, re.DOTALL) + + # If no code blocks are found, return the whole response + if not matches_backticks: + return response + + # Process each match to remove standalone compute() or test() lines + processed_code_blocks = [] + for code_block in matches_backticks: + # Remove standalone compute() or test() lines + code_block = re.sub(r'^compute\(.*?\)\s*$', '', code_block, flags=re.MULTILINE) + code_block = re.sub(r'^test\(.*?\)\s*$', '', code_block, flags=re.MULTILINE) + processed_code_blocks.append(code_block.strip()) + + # Combine and return all processed code blocks + return "\n\n".join(processed_code_blocks) + + +def compute(user_prompt, model_version, conversation_history, apiKey): + # Use only the last entry from the history + if conversation_history: + conversation_history = [conversation_history[-1]] + + # Escape special characters or handle raw strings in conversation history + escaped_history = [] + for entry in conversation_history: + # Example of escaping curly braces + prompt = entry['prompt'].replace("{", "{{").replace("}", "}}") + response = entry['response'].replace("{", "{{").replace("}", "}}") + escaped_history.append(("user", prompt)) + escaped_history.append(("assistant", response)) + + # Use the escaped history for constructing messages + messages = [("system", openaiSystemContent)] + escaped_history + messages.append(("user", "{text}")) + + # Create a ChatPromptTemplate from the messages + chat_prompt = ChatPromptTemplate.from_messages(messages) + + # Initialize the ChatOpenAI model + chat_model = ChatOpenAI(openai_api_key=apiKey, model=model_version) + chain = chat_prompt | chat_model + + # Query + response = chain.invoke({"text": user_prompt}) + + # Keep only the python code + code = extract_python_code(response.content) + + return {'response': code, 'model': model_version} + + + +if __name__ == "__main__": + try: + # Read JSON string from stdin + input_json = sys.stdin.read() + + # Parse the JSON input + data = json.loads(input_json) + + # Extract the arguments from the parsed JSON + user_prompt = data['userMessage'] + # model_version = data.get('selectedModel', 'gpt-4') + conversation_history = data.get('conversationHistory', []) + apiKey = data["apiKey"] + + # Call the compute function and get the result + result = compute(user_prompt, 'gpt-4o', conversation_history, apiKey) + + # Print the result as a JSON string + print(json.dumps(result)) + except Exception as e: + # Capture and print the full stack trace + error_traceback = traceback.format_exc() + print(json.dumps({"error": str(e), "traceback": error_traceback})) diff --git a/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/agents/gpt-4_python_compute/generate/specs.json b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/agents/gpt-4_python_compute/generate/specs.json new file mode 100644 index 00000000..b9b731f6 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/agents/gpt-4_python_compute/generate/specs.json @@ -0,0 +1,30 @@ +{ + "block": { + "information": { + "id": "", + "name": "", + "description": "", + "system_version": "" + }, + "parameters": {}, + "action": { + "languages": { + "name": "python", + "version": "3.9" + }, + "container_uuid": "", + "container_image_uuid": "", + "block_source": "" + }, + "views": { + "node": { + "html": "", + "pos_x": "300", + "pos_y": "200", + "pos_z": "999, this is the z-index for 2D canvas" + } + }, + "controllers": {}, + "events": [] + } +} diff --git a/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/agents/gpt-4_python_view/generate/computations.py b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/agents/gpt-4_python_view/generate/computations.py new file mode 100644 index 00000000..2d6cd1d5 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/agents/gpt-4_python_view/generate/computations.py @@ -0,0 +1,141 @@ +import json +import re +import sys +import traceback + +from langchain.prompts import ChatPromptTemplate +from langchain_openai import ChatOpenAI + +# Define system context +openaiSystemContent = """You are an assistant that generates python code and returns it in a way that must follow the template below. Your goal is to generate a view.html file that satisfy the user requirement. +Most importantly, you must rely on the prompt to generate the html_template file that satisfy the user request. The html should contain everything to display in a brownser and must rely CDN or skypack when needed. +You absolutely need to give a python code section without abbreviation that follows the template. Do not put code lines at the root, but give only the functions and imports. + +By default, when requested to do change or add to the code, modify the latest code section. But when the user ask to do it on another section, do so. + +In the template, the function compute contains the code and the function test contains a series of call to compute that runs and prints multiple tests. + +Don't insert a __main__ section. + +Template: +from string import Template + +def compute(in1): + '''Generates an HTML file with a unique name and returns the file name.''' + + html_template = Template(''' + + + + Hello Block View + + + $in1 + + + ''') + + # Build and save the html file + html_path = f"view.html" + html_code = html_template.substitute(in1=in1) + with open(html_path, "w") as file: + file.write(html_code) + + return {{'html': f"view.html"}} + +def test(): + '''Test the compute function.''' + + print('Running test') + result = compute('Hello view block') + print(f"Generated HTML file: {{result['html']}}") +""" + + +def extract_python_code(response): + """ + Extracts Python code blocks from a given text, excluding standalone compute() or test() calls. + Assumes that Python code is formatted with triple backticks. + If no Python code blocks are found, returns the whole response. + """ + + # Pattern to match code blocks fenced by triple backticks + pattern_backticks = r"```python\n(.*?)```" + + # Extract code blocks fenced by triple backticks + matches_backticks = re.findall(pattern_backticks, response, re.DOTALL) + + # If no code blocks are found, return the whole response + if not matches_backticks: + return response + + # Process each match to remove standalone compute() or test() lines + processed_code_blocks = [] + for code_block in matches_backticks: + # Remove standalone compute() or test() lines + code_block = re.sub(r'^compute\(.*?\)\s*$', '', code_block, flags=re.MULTILINE) + code_block = re.sub(r'^test\(.*?\)\s*$', '', code_block, flags=re.MULTILINE) + processed_code_blocks.append(code_block.strip()) + + # Combine and return all processed code blocks + return "\n\n".join(processed_code_blocks) + + +def compute(user_prompt, model_version, conversation_history, apiKey): + # Use only the last entry from the history + if conversation_history: + conversation_history = [conversation_history[-1]] + + # Escape special characters or handle raw strings in conversation history + escaped_history = [] + for entry in conversation_history: + # Example of escaping curly braces + prompt = entry['prompt'].replace("{", "{{").replace("}", "}}") + response = entry['response'].replace("{", "{{").replace("}", "}}") + escaped_history.append(("user", prompt)) + escaped_history.append(("assistant", response)) + + # Use the escaped history for constructing messages + messages = [("system", openaiSystemContent)] + escaped_history + messages.append(("user", "{text}")) + + # Create a ChatPromptTemplate from the messages + chat_prompt = ChatPromptTemplate.from_messages(messages) + + # Initialize the ChatOpenAI model + chat_model = ChatOpenAI(openai_api_key=apiKey, model=model_version) + chain = chat_prompt | chat_model + + # Query + response = chain.invoke({"text": user_prompt}) + + # Keep only the python code + code = extract_python_code(response.content) + + return {'response': code, 'model': model_version} + + + +if __name__ == "__main__": + try: + # Read JSON string from stdin + input_json = sys.stdin.read() + + # Parse the JSON input + data = json.loads(input_json) + + # Extract the arguments from the parsed JSON + user_prompt = data['userMessage'] + # model_version = data.get('selectedModel', 'gpt-4') + conversation_history = data.get('conversationHistory', []) + apiKey = data['apiKey'] + + # Call the compute function and get the result + result = compute(user_prompt, 'gpt-4o', conversation_history, apiKey) + + # Print the result as a JSON string + print(json.dumps(result)) + except Exception as e: + # Capture and print the full stack trace + error_traceback = traceback.format_exc() + print(json.dumps({"error": str(e), "traceback": error_traceback})) diff --git a/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/agents/gpt-4_python_view/generate/specs.json b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/agents/gpt-4_python_view/generate/specs.json new file mode 100644 index 00000000..b9b731f6 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/agents/gpt-4_python_view/generate/specs.json @@ -0,0 +1,30 @@ +{ + "block": { + "information": { + "id": "", + "name": "", + "description": "", + "system_version": "" + }, + "parameters": {}, + "action": { + "languages": { + "name": "python", + "version": "3.9" + }, + "container_uuid": "", + "container_image_uuid": "", + "block_source": "" + }, + "views": { + "node": { + "html": "", + "pos_x": "300", + "pos_y": "200", + "pos_z": "999, this is the z-index for 2D canvas" + } + }, + "controllers": {}, + "events": [] + } +} diff --git a/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/computations.py b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/computations.py new file mode 100644 index 00000000..824df2d5 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/computations.py @@ -0,0 +1,48 @@ +import uuid +import os +import zipfile +import html + +def escape_content(content): + # First escape using html.escape + escaped_content = html.escape(content) + # Then manually replace backticks with their HTML entity + escaped_content = escaped_content.replace('`', '`').replace('$', '$') + return escaped_content + +def compute(initial_content, api_key, image_paths): + """Tool to generate HTML apps interfaces using the OpenAI API. + + Inputs: + api_key (str): API key to be included in the generated HTML page. + initial_content (str): Initial HTML content to be embedded in the generated HTML page. + image_paths (list): List of image paths to be included and saved locally. + + Outputs: + dict: A dictionary with the key 'html' and the value being the name of the generated HTML file. + """ + + # Load the HTML template + with open('template.html', 'r') as file: + html_template = file.read() + + # Escape the initial content and API key + escaped_initial_content = escape_content(initial_content) + escaped_api_key = escape_content(api_key) + + # Replace the placeholder with the actual content and image paths + html_code = (html_template.replace('<< api_key >>', escaped_api_key) + .replace('<< initial_content >>', escaped_initial_content)) + + # Write the file + unique_id = str(uuid.uuid4()) + html_path = f"/files/viz_{unique_id}.html" + + with open(html_path, "w") as file: + file.write(html_code) + + return {"html": f"viz_{unique_id}.html"} + +def test(): + """Test the compute function.""" + print("Running test") diff --git a/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/mona.png b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/mona.png new file mode 100644 index 00000000..cedc91aa Binary files /dev/null and b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/mona.png differ diff --git a/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/requirements.txt b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/requirements.txt new file mode 100644 index 00000000..99a80913 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/requirements.txt @@ -0,0 +1,2 @@ + + diff --git a/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/robocat.png b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/robocat.png new file mode 100644 index 00000000..e9f1ae0f Binary files /dev/null and b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/robocat.png differ diff --git a/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/specs.json b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/specs.json new file mode 100644 index 00000000..abf11e24 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/specs.json @@ -0,0 +1,70 @@ +{ + "information": { + "id": "interface-maker", + "name": "Interface Maker", + "description": "Tool to generate HTML apps interfaces using the OpenAI API.\n\nInputs:\n api_key (str): API key to be included in the generated HTML page.\n initial_content (str): Initial HTML content to be embedded in the generated HTML page.\n image_paths (list): List of image paths to be included and saved locally.\n\nOutputs:\n dict: A dictionary with the key 'html' and the value being the name of the generated HTML file.", + "system_versions": [ + "0.1" + ], + "block_version": "1.0", + "block_source": "", + "block_type": "view" + }, + "inputs": { + "initial_content": { + "type": "Any", + "connections": [] + }, + "api_key": { + "type": "Any", + "connections": [] + }, + "image_paths": { + "type": "Any", + "connections": [] + } + }, + "outputs": { + "html": { + "type": "Any", + "connections": [] + } + }, + "action": { + "container": { + "image": "interface-maker", + "version": "interface-maker-ool7kd5xda3sw", + "command_line": [ + "python", + "entrypoint.py" + ] + } + }, + "views": { + "node": { + "active": "true", + "title_bar": { + "background_color": "#0099ff" + }, + "preview": { + "active": "true" + }, + "html": "", + "pos_x": 0, + "pos_y": 0, + "pos_z": "999", + "order": { + "input": [ + "initial_content", + "api_key", + "image_paths" + ], + "output": [ + "html" + ] + } + }, + "mode": "modal" + }, + "events": {} +} \ No newline at end of file diff --git a/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/template.html b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/template.html new file mode 100644 index 00000000..8aecca1f --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/interface-maker-ool7kd5xa3sw/template.html @@ -0,0 +1,603 @@ + + + + + + Chat and Iframe + + + +
+
+
+ + +
+
+
+
+
+
View
+
HTML
+
Response
+
+
+ + + + +
+
+ +
+
+

+        
+
+

+        
+
+ + + + diff --git a/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/Dockerfile b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/Dockerfile new file mode 100644 index 00000000..ac70a253 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.9 + +WORKDIR /app + +COPY requirements.txt . + +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . diff --git a/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/computations.py b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/computations.py new file mode 100644 index 00000000..c99d109b --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/computations.py @@ -0,0 +1,22 @@ +import os + +def compute(): + '''List all image files in the current directory, rename them by appending 'img_' in front, and save them with the same name. Return the filenames of the renamed files.''' + + image_extensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff'] + renamed_image_files = [] + + current_directory = os.path.dirname(os.path.abspath(__file__)) + for file in os.listdir(current_directory): + if any(file.lower().endswith(ext) for ext in image_extensions): + new_filename = 'img_' + file + os.rename(os.path.join(current_directory, file), os.path.join(current_directory, new_filename)) + renamed_image_files.append(new_filename) + + return {'image_files': renamed_image_files} + +def test(): + # Test the function without input, assumes known files in the current directory + expected_output = {'renamed_image_files': ['img_image1.jpg', 'img_photo.png', 'img_pic.gif']} + result = compute() + print('Test Passed:', result == expected_output, 'Output:', result) \ No newline at end of file diff --git a/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/cover-image.png b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/cover-image.png new file mode 100644 index 00000000..a33c4599 Binary files /dev/null and b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/cover-image.png differ diff --git a/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/mona.png b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/mona.png new file mode 100644 index 00000000..cedc91aa Binary files /dev/null and b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/mona.png differ diff --git a/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/rain.png b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/rain.png new file mode 100644 index 00000000..01109885 Binary files /dev/null and b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/rain.png differ diff --git a/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/requirements.txt b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/requirements.txt new file mode 100644 index 00000000..5873a222 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/requirements.txt @@ -0,0 +1 @@ +Pillow \ No newline at end of file diff --git a/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/small_cute_cat.png b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/small_cute_cat.png new file mode 100644 index 00000000..c5c397d3 Binary files /dev/null and b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/small_cute_cat.png differ diff --git a/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/specs.json b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/specs.json new file mode 100644 index 00000000..9178caef --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/new-python-i3a2bb98agbh/specs.json @@ -0,0 +1,52 @@ +{ + "information": { + "id": "new-python", + "name": "Images Block", + "description": "List all image files in the current directory, rename them by appending 'img_' in front, and save them with the same name. Return the filenames of the renamed files.", + "system_versions": [ + "0.1" + ], + "block_version": "block version number", + "block_source": "core/blocks/new-python", + "block_type": "compute" + }, + "inputs": {}, + "outputs": { + "image_files": { + "type": "Any", + "connections": [] + } + }, + "action": { + "container": { + "image": "new-python", + "version": "new-python-i3a02bb938agbh", + "command_line": [ + "python", + "-u", + "entrypoint.py" + ] + } + }, + "views": { + "node": { + "active": "True or False", + "title_bar": { + "background_color": "#6b2be0" + }, + "preview": {}, + "html": "", + "pos_x": 0, + "pos_y": 0, + "pos_z": "999", + "behavior": "modal", + "order": { + "input": [], + "output": [ + "image_files" + ] + } + } + }, + "events": {} +} \ No newline at end of file diff --git a/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/Dockerfile b/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/Dockerfile new file mode 100644 index 00000000..83464ec2 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.10-slim + +WORKDIR /app + +COPY requirements.txt . + +RUN pip install --no-cache-dir -r requirements.txt + +COPY computations.py . diff --git a/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/computations.py b/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/computations.py new file mode 100644 index 00000000..665c7dfc --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/computations.py @@ -0,0 +1,43 @@ +from openai import OpenAI +import re +import json + +def compute(prompt, api_key): + """ + Communicates with the OpenAI API to generate a completion based on the given role and prompt. + + Args: + role (str): The role of the system for the chat model (e.g., "You are a copywriter..."). + prompt (str): The prompt to be provided to the user in the chat model. + api_key (str): The API key to authenticate with the OpenAI API. + + Returns: + str: The content of the generated response from the OpenAI API. + """ + + role = """You are an assistant that takes a user input text and generates a detailed textual description of a web application (e.g., tool) without code. + Importantly, give only a textual description, no code should be given. + + Note that this web application needs to be in one index.html file without a backend. + You need to describe the application, + give all the components of the application along with technical description and + describe the application dynamics and outline of how to implement it. + """ + + client = OpenAI(api_key=api_key) + completion = client.chat.completions.create( + model="gpt-4o", + messages=[ + {"role": "system", "content": role}, + {"role": "user", "content": prompt} + ], + temperature=0.1 + ) + + # Extract the response content + response_content = completion.choices[0].message.content + + return {"response": response_content} + +def test(): + """Test the compute function.""" diff --git a/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/cover-image.png b/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/cover-image.png new file mode 100644 index 00000000..02aa6d60 Binary files /dev/null and b/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/cover-image.png differ diff --git a/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/requirements.txt b/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/requirements.txt new file mode 100644 index 00000000..9ff727d7 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/requirements.txt @@ -0,0 +1 @@ +openai==1.34.0 diff --git a/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/specs.json b/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/specs.json new file mode 100644 index 00000000..2f0599c8 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/openai-agent-1-tuo6ndtm42rc/specs.json @@ -0,0 +1,80 @@ +{ + "information": { + "id": "openai-agent-1", + "name": "OpenAI Agent", + "description": "Communicates with the OpenAI API to generate a completion based on the given role and prompt.\n\nArgs:\n role (str): The role of the system for the chat model (e.g., \"You are a copywriter...\").\n prompt (str): The prompt to be provided to the user in the chat model.\n api_key (str): The API key to authenticate with the OpenAI API.\n\nReturns:\n str: The content of the generated response from the OpenAI API.", + "system_versions": [ + "0.1" + ], + "block_version": "block version number", + "block_source": "", + "block_type": "compute" + }, + "inputs": { + "prompt": { + "type": "Any", + "connections": [ + { + "block": "text-n4mzvwd9a94p", + "variable": "text" + } + ] + }, + "api_key": { + "type": "Any", + "connections": [ + { + "block": "password-cra270gb0hn0", + "variable": "password" + } + ] + } + }, + "outputs": { + "response": { + "type": "Any", + "connections": [ + { + "block": "text-as-html-ttf7h7l5j6rb", + "variable": "data_view" + }, + { + "block": "text-to-html-app-r6kt1w8j4zfy", + "variable": "prompt" + } + ] + } + }, + "action": { + "container": { + "image": "openai-agent-1", + "version": "openai-agent-1-tuo6ndtm42rc", + "command_line": [ + "python", + "entrypoint.py" + ] + } + }, + "views": { + "node": { + "active": "True", + "title_bar": {}, + "preview": {}, + "html": "", + "pos_x": "613", + "pos_y": "371", + "pos_z": "999", + "behavior": "modal", + "order": { + "input": [ + "prompt", + "api_key" + ], + "output": [ + "response" + ] + } + } + }, + "events": {} +} \ No newline at end of file diff --git a/frontend/core/pipelines/pipeline-text-to-game/pipeline.json b/frontend/core/pipelines/pipeline-text-to-game/pipeline.json new file mode 100644 index 00000000..59739158 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/pipeline.json @@ -0,0 +1,505 @@ +{ + "pipeline": { + "password-cra270gb0hn0": { + "information": { + "id": "password", + "name": "Password", + "description": "Password block parameter input.", + "system_versions": ["0.1"], + "block_version": "0.1", + "block_source": "core/blocks", + "block_type": "entry" + }, + "inputs": {}, + "outputs": { + "password": { + "type": "Any", + "connections": [ + { + "block": "openai-agent-1-tuo6ndtm42rc", + "variable": "api_key" + }, + { + "block": "text-to-html-app-r6kt1w8j4zfy", + "variable": "api_key" + }, + { + "block": "interface-maker-ool7kd5xa3sw", + "variable": "api_key" + } + ] + } + }, + "action": { + "container": { + "image": "", + "version": "", + "command_line": [] + }, + "parameters": { + "password": { + "value": "", + "type": "Any" + } + } + }, + "views": { + "node": { + "active": "true", + "title_bar": { + "background_color": "#909090" + }, + "preview": {}, + "html": "", + "pos_x": "112", + "pos_y": "546", + "pos_z": "999, this is the z-index for 2D canvas", + "order": { + "input": [], + "output": ["password"] + } + } + }, + "events": {} + }, + "interface-maker-ool7kd5xa3sw": { + "information": { + "id": "interface-maker", + "name": "Interface Maker", + "description": "Tool to generate HTML apps interfaces using the OpenAI API.\n\nInputs:\n api_key (str): API key to be included in the generated HTML page.\n initial_content (str): Initial HTML content to be embedded in the generated HTML page.\n image_paths (list): List of image paths to be included and saved locally.\n\nOutputs:\n dict: A dictionary with the key 'html' and the value being the name of the generated HTML file.", + "system_versions": ["0.1"], + "block_version": "1.0", + "block_source": "", + "block_type": "view" + }, + "inputs": { + "initial_content": { + "type": "Any", + "connections": [ + { + "block": "text-to-html-app-r6kt1w8j4zfy", + "variable": "content" + } + ] + }, + "api_key": { + "type": "Any", + "connections": [ + { + "block": "password-cra270gb0hn0", + "variable": "password" + } + ] + }, + "image_paths": { + "type": "Any", + "connections": [ + { + "block": "new-python-i3a2bb98agbh", + "variable": "image_files" + } + ] + } + }, + "outputs": { + "html": { + "type": "Any", + "connections": [] + } + }, + "action": { + "container": { + "image": "interface-maker", + "version": "interface-maker-ool7kd5xda3sw", + "command_line": ["python", "entrypoint.py"] + } + }, + "views": { + "node": { + "active": "true", + "title_bar": { + "background_color": "#0099ff" + }, + "preview": { + "active": "true" + }, + "html": "", + "pos_x": "2051", + "pos_y": "635", + "pos_z": "999", + "order": { + "input": ["initial_content", "api_key", "image_paths"], + "output": ["html"] + } + }, + "mode": "modal" + }, + "events": {} + }, + "text-to-html-app-r6kt1w8j4zfy": { + "information": { + "id": "text-to-html-app", + "name": "Text to HTML App", + "description": "Communicates with the OpenAI API to generate an HTML page based on the given prompt and accessible assets.\n\nArgs:\n prompt (str): The detailed description for the application to be built.\n api_key (str): The API key to authenticate with the OpenAI API.\n\nReturns:\n dict: A dictionary containing the generated HTML page.", + "system_versions": ["0.1"], + "block_version": "block version number", + "block_source": "", + "block_type": "compute" + }, + "inputs": { + "prompt": { + "type": "Any", + "connections": [ + { + "block": "openai-agent-1-tuo6ndtm42rc", + "variable": "response" + } + ] + }, + "api_key": { + "type": "Any", + "connections": [ + { + "block": "password-cra270gb0hn0", + "variable": "password" + } + ] + } + }, + "outputs": { + "htlm": { + "type": "Any", + "connections": [ + { + "block": "view-html-8qh8d7kxxrph", + "variable": "html_path" + } + ] + }, + "content": { + "type": "Any", + "connections": [ + { + "block": "interface-maker-ool7kd5xa3sw", + "variable": "initial_content" + } + ] + } + }, + "action": { + "container": { + "image": "text-to-html-app", + "version": "text-to-html-app-rd6kt1w8j4zfy", + "command_line": ["python", "entrypoint.py"] + } + }, + "views": { + "node": { + "active": "True", + "title_bar": {}, + "preview": {}, + "html": "", + "pos_x": "1330", + "pos_y": "414", + "pos_z": "999", + "behavior": "modal", + "order": { + "input": ["prompt", "api_key"], + "output": ["htlm", "content"] + } + } + }, + "events": {} + }, + "openai-agent-1-tuo6ndtm42rc": { + "information": { + "id": "openai-agent-1", + "name": "OpenAI Agent", + "description": "Communicates with the OpenAI API to generate a completion based on the given role and prompt.\n\nArgs:\n role (str): The role of the system for the chat model (e.g., \"You are a copywriter...\").\n prompt (str): The prompt to be provided to the user in the chat model.\n api_key (str): The API key to authenticate with the OpenAI API.\n\nReturns:\n str: The content of the generated response from the OpenAI API.", + "system_versions": ["0.1"], + "block_version": "block version number", + "block_source": "", + "block_type": "compute" + }, + "inputs": { + "prompt": { + "type": "Any", + "connections": [ + { + "block": "text-n4mzvwd9a94p", + "variable": "text" + } + ] + }, + "api_key": { + "type": "Any", + "connections": [ + { + "block": "password-cra270gb0hn0", + "variable": "password" + } + ] + } + }, + "outputs": { + "response": { + "type": "Any", + "connections": [ + { + "block": "text-as-html-ttf7h7l5j6rb", + "variable": "data_view" + }, + { + "block": "text-to-html-app-r6kt1w8j4zfy", + "variable": "prompt" + } + ] + } + }, + "action": { + "container": { + "image": "openai-agent-1", + "version": "openai-agent-1-tuo6ndtm42rc", + "command_line": ["python", "entrypoint.py"] + } + }, + "views": { + "node": { + "active": "True", + "title_bar": {}, + "preview": {}, + "html": "", + "pos_x": "613", + "pos_y": "371", + "pos_z": "999", + "behavior": "modal", + "order": { + "input": ["prompt", "api_key"], + "output": ["response"] + } + } + }, + "events": {} + }, + "view-html-8qh8d7kxxrph": { + "information": { + "id": "view-html", + "name": "View HTML", + "description": "Display the input HTML page.\n\nInputs:\n html_path: Path to the HTML file to be displayed.\n\nOutputs:\n dict: A dictionary with the key 'html' and the value being the name of the generated HTML file.", + "system_versions": ["0.1"], + "block_version": "1.0", + "block_source": "core/blocks/view-html", + "block_type": "view" + }, + "inputs": { + "html_path": { + "type": "Any", + "connections": [ + { + "block": "text-to-html-app-r6kt1w8j4zfy", + "variable": "htlm" + } + ] + } + }, + "outputs": { + "html": { + "type": "Any", + "connections": [] + } + }, + "action": { + "container": { + "image": "view-html", + "version": "view-html-8qh8d7kxxrph", + "command_line": ["python", "entrypoint.py"] + } + }, + "views": { + "node": { + "active": "true", + "title_bar": { + "background_color": "#0099ff" + }, + "preview": { + "active": "true" + }, + "html": "", + "pos_x": "1784", + "pos_y": "260", + "pos_z": "999", + "order": { + "input": ["html_path"], + "output": ["html"] + } + }, + "mode": "modal" + }, + "events": {} + }, + "text-as-html-ttf7h7l5j6rb": { + "information": { + "id": "text-as-html", + "name": "Text as HTML", + "description": "Generates an HTML file that displays the provided data and returns the file name.\n\nThis function takes a string, dictionary, or list of dictionaries and generates\nan HTML file to visually present the data. The generated HTML file is saved with\na unique name to avoid conflicts. The HTML content includes styling and scripts\nto format the data for better readability.\n\nParameters:\ndata_view (str, dict, or list): The data to be displayed in the gallery. It can be:\n - A single string\n - A single dictionary\n - A list of strings or dictionaries\n\nReturns:\ndict: A dictionary containing the key 'html' with the value being the name of the\ngenerated HTML file.", + "system_versions": ["0.1"], + "block_version": "block version number", + "block_source": "core/blocks/text-as-html", + "block_type": "view" + }, + "inputs": { + "data_view": { + "type": "Any", + "connections": [ + { + "block": "openai-agent-1-tuo6ndtm42rc", + "variable": "response" + } + ] + } + }, + "outputs": { + "html": { + "type": "Any", + "connections": [] + } + }, + "action": { + "container": { + "image": "text-as-html", + "version": "text-as-html-ttf7h7l5j6rb", + "command_line": ["python", "entrypoint.py"] + } + }, + "views": { + "node": { + "active": "True", + "title_bar": { + "background_color": "#D55908" + }, + "preview": { + "active": "true" + }, + "html": "", + "pos_x": "989", + "pos_y": "258", + "pos_z": "999, this is the z-index for 2D canvas", + "order": { + "input": ["data_view"], + "output": ["html"] + } + }, + "mode": "modal" + }, + "events": {} + }, + "text-n4mzvwd9a94p": { + "information": { + "id": "text", + "name": "Text", + "description": "Text block parameter input.", + "system_versions": ["0.1"], + "block_version": "0.1", + "block_source": "core/blocks", + "block_type": "entry" + }, + "inputs": {}, + "outputs": { + "text": { + "type": "str", + "connections": [ + { + "block": "openai-agent-1-tuo6ndtm42rc", + "variable": "prompt" + } + ] + } + }, + "action": { + "container": { + "image": "", + "version": "", + "command_line": [] + }, + "parameters": { + "text": { + "value": "", + "type": "str" + } + } + }, + "views": { + "node": { + "active": "true", + "title_bar": { + "background_color": "#909090" + }, + "preview": {}, + "html": "", + "pos_x": "31", + "pos_y": "146", + "pos_z": "999, this is the z-index for 2D canvas", + "order": { + "input": [], + "output": ["text"] + } + } + }, + "events": {} + }, + "new-python-i3a2bb98agbh": { + "information": { + "id": "new-python", + "name": "Images Block", + "description": "List all image files in the current directory, rename them by appending 'img_' in front, and save them with the same name. Return the filenames of the renamed files.", + "system_versions": ["0.1"], + "block_version": "block version number", + "block_source": "core/blocks/new-python", + "block_type": "compute" + }, + "inputs": {}, + "outputs": { + "image_files": { + "type": "Any", + "connections": [ + { + "block": "interface-maker-ool7kd5xa3sw", + "variable": "image_paths" + } + ] + } + }, + "action": { + "container": { + "image": "new-python", + "version": "new-python-i3a02bb938agbh", + "command_line": ["python", "-u", "entrypoint.py"] + } + }, + "views": { + "node": { + "active": "True or False", + "title_bar": { + "background_color": "#6b2be0" + }, + "preview": {}, + "html": "", + "pos_x": "1585", + "pos_y": "806", + "pos_z": "999", + "behavior": "modal", + "order": { + "input": [], + "output": ["image_files"] + } + } + }, + "events": {} + } + }, + "sink": "", + "build": "", + "name": "text-to-game", + "id": "pipeline-2l3k4j5m6n7o", + "description": "Pipeline to generate a fully frontend game, given prompt and accessible assets. Note: make sure to encapsulate the API key in quotes." +} diff --git a/frontend/core/pipelines/pipeline-text-to-game/text-as-html-ttf7h7l5j6rb/Dockerfile b/frontend/core/pipelines/pipeline-text-to-game/text-as-html-ttf7h7l5j6rb/Dockerfile new file mode 100644 index 00000000..f933f667 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/text-as-html-ttf7h7l5j6rb/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.9-slim + +WORKDIR /app + +COPY requirements.txt . + +RUN pip install --no-cache-dir -r requirements.txt + +COPY computations.py . diff --git a/frontend/core/pipelines/pipeline-text-to-game/text-as-html-ttf7h7l5j6rb/computations.py b/frontend/core/pipelines/pipeline-text-to-game/text-as-html-ttf7h7l5j6rb/computations.py new file mode 100644 index 00000000..59d8ef8b --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/text-as-html-ttf7h7l5j6rb/computations.py @@ -0,0 +1,120 @@ +import json +import uuid + +def compute(data_view): + """Generates an HTML file that displays the provided data and returns the file name. + + This function takes a string, dictionary, or list of dictionaries and generates + an HTML file to visually present the data. The generated HTML file is saved with + a unique name to avoid conflicts. The HTML content includes styling and scripts + to format the data for better readability. + + Parameters: + data_view (str, dict, or list): The data to be displayed in the gallery. It can be: + - A single string + - A single dictionary + - A list of strings or dictionaries + + Returns: + dict: A dictionary containing the key 'html' with the value being the name of the + generated HTML file. + """ + + html_template = """ + + + + + Data Gallery + + + + + + + + + + + + + """ + # Ensure data_view is always a list + if isinstance(data_view, (str, dict)): + data_view = [data_view] + + unique_id = str(uuid.uuid4()) + html_path = f"/files/data_viz_{unique_id}.html" + data_view_str = json.dumps(data_view, indent=4) # Properly escape JSON for embedding in JavaScript + html_code = html_template.replace("$data_paths", json.dumps(data_view)) + + # Write the file + with open(html_path, "w") as file: + file.write(html_code) + + return {"html": f"data_viz_{unique_id}.html"} + +def test(): + """Test the compute function with various data types and print the test cases and their results.""" + test_cases = [ + "Single string\nwith newline", + ["List", "of\nstrings"], + {"name": "Alice", "age": 30}, + [{"name": "Bob", "age": 25}, {"name": "Charlie", "age": 35}], + json.dumps({"name": "Dave", "age": 40}), + [json.dumps({"name": "Eve", "age": 45}), json.dumps({"name": "Frank", "age": 50})] + ] + + for i, case in enumerate(test_cases): + result = compute(case) + print(f"Test case {i+1}: Input - {case}") + print(f"Result: {result}\n") diff --git a/frontend/core/pipelines/pipeline-text-to-game/text-as-html-ttf7h7l5j6rb/cover-image.png b/frontend/core/pipelines/pipeline-text-to-game/text-as-html-ttf7h7l5j6rb/cover-image.png new file mode 100644 index 00000000..c3064a9e Binary files /dev/null and b/frontend/core/pipelines/pipeline-text-to-game/text-as-html-ttf7h7l5j6rb/cover-image.png differ diff --git a/frontend/core/pipelines/pipeline-text-to-game/text-as-html-ttf7h7l5j6rb/requirements.txt b/frontend/core/pipelines/pipeline-text-to-game/text-as-html-ttf7h7l5j6rb/requirements.txt new file mode 100644 index 00000000..e69de29b diff --git a/frontend/core/pipelines/pipeline-text-to-game/text-as-html-ttf7h7l5j6rb/specs.json b/frontend/core/pipelines/pipeline-text-to-game/text-as-html-ttf7h7l5j6rb/specs.json new file mode 100644 index 00000000..95a21e7d --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/text-as-html-ttf7h7l5j6rb/specs.json @@ -0,0 +1,65 @@ +{ + "information": { + "id": "text-as-html", + "name": "Text as HTML", + "description": "Generates an HTML file that displays the provided data and returns the file name.\n\nThis function takes a string, dictionary, or list of dictionaries and generates\nan HTML file to visually present the data. The generated HTML file is saved with\na unique name to avoid conflicts. The HTML content includes styling and scripts\nto format the data for better readability.\n\nParameters:\ndata_view (str, dict, or list): The data to be displayed in the gallery. It can be:\n - A single string\n - A single dictionary\n - A list of strings or dictionaries\n\nReturns:\ndict: A dictionary containing the key 'html' with the value being the name of the\ngenerated HTML file.", + "system_versions": [ + "0.1" + ], + "block_version": "block version number", + "block_source": "core/blocks/text-as-html", + "block_type": "view" + }, + "inputs": { + "data_view": { + "type": "Any", + "connections": [ + { + "block": "openai-agent-1-tuo6ndtm42rc", + "variable": "response" + } + ] + } + }, + "outputs": { + "html": { + "type": "Any", + "connections": [] + } + }, + "action": { + "container": { + "image": "text-as-html", + "version": "text-as-html-ttf7h7l5j6rb", + "command_line": [ + "python", + "entrypoint.py" + ] + } + }, + "views": { + "node": { + "active": "True", + "title_bar": { + "background_color": "#D55908" + }, + "preview": { + "active": "true" + }, + "html": "", + "pos_x": "989", + "pos_y": "258", + "pos_z": "999, this is the z-index for 2D canvas", + "order": { + "input": [ + "data_view" + ], + "output": [ + "html" + ] + } + }, + "mode": "modal" + }, + "events": {} +} \ No newline at end of file diff --git a/frontend/core/pipelines/pipeline-text-to-game/text-to-html-app-r6kt1w8j4zfy/Dockerfile b/frontend/core/pipelines/pipeline-text-to-game/text-to-html-app-r6kt1w8j4zfy/Dockerfile new file mode 100644 index 00000000..83464ec2 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/text-to-html-app-r6kt1w8j4zfy/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.10-slim + +WORKDIR /app + +COPY requirements.txt . + +RUN pip install --no-cache-dir -r requirements.txt + +COPY computations.py . diff --git a/frontend/core/pipelines/pipeline-text-to-game/text-to-html-app-r6kt1w8j4zfy/computations.py b/frontend/core/pipelines/pipeline-text-to-game/text-to-html-app-r6kt1w8j4zfy/computations.py new file mode 100644 index 00000000..135d5b7f --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/text-to-html-app-r6kt1w8j4zfy/computations.py @@ -0,0 +1,72 @@ +from openai import OpenAI +import re + +def compute(prompt, api_key): + """ + Communicates with the OpenAI API to generate an HTML page based on the given prompt and accessible assets. + + Args: + prompt (str): The detailed description for the application to be built. + api_key (str): The API key to authenticate with the OpenAI API. + + Returns: + dict: A dictionary containing the generated HTML page. + """ + + role = """You are an assistant that generates a full HTML page based on user input. All the code should be in one HTML page and use CDN. + Insert in the head ld+json metadata describing the application in a way that follows the exact example template below. + Example for a photo editor application: + """ + + print(role) + + preamble = """Build an application based on the following detailed description and use web icons such as font awesome instead of images. + Resize the images accordingly based on what they are and be sized to fit the canvas. + Be careful about flex and positions. + Stretch the canvas to the parent. + Do not use alerts. + Importantly, implement all features and functionalities.\n\n""" + + prompt_to_send = preamble + prompt + + client = OpenAI(api_key=api_key) + completion = client.chat.completions.create( + model="gpt-4o", + messages=[ + {"role": "system", "content": role}, + {"role": "user", "content": prompt} + ], + temperature=0.0 + ) + + # Extract the response content + response_content = completion.choices[0].message.content + print(response_content) + + # Find the HTML content in the response + html_match = re.search(r'```html\n(.*?)\n```', response_content, re.DOTALL) + + file_path = 'generated_app.html' + with open(file_path, 'w', encoding='utf-8') as file: + file.write(html_match.group(1)) + print(f"File saved at: {file_path}") + + return {"htlm": file_path, "content": html_match.group(1)} + +def test(): + """Test the compute function.""" diff --git a/frontend/core/pipelines/pipeline-text-to-game/text-to-html-app-r6kt1w8j4zfy/requirements.txt b/frontend/core/pipelines/pipeline-text-to-game/text-to-html-app-r6kt1w8j4zfy/requirements.txt new file mode 100644 index 00000000..9ff727d7 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/text-to-html-app-r6kt1w8j4zfy/requirements.txt @@ -0,0 +1 @@ +openai==1.34.0 diff --git a/frontend/core/pipelines/pipeline-text-to-game/text-to-html-app-r6kt1w8j4zfy/specs.json b/frontend/core/pipelines/pipeline-text-to-game/text-to-html-app-r6kt1w8j4zfy/specs.json new file mode 100644 index 00000000..8799d0e8 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/text-to-html-app-r6kt1w8j4zfy/specs.json @@ -0,0 +1,86 @@ +{ + "information": { + "id": "text-to-html-app", + "name": "Text to HTML App", + "description": "Communicates with the OpenAI API to generate an HTML page based on the given prompt and accessible assets.\n\nArgs:\n prompt (str): The detailed description for the application to be built.\n api_key (str): The API key to authenticate with the OpenAI API.\n\nReturns:\n dict: A dictionary containing the generated HTML page.", + "system_versions": [ + "0.1" + ], + "block_version": "block version number", + "block_source": "", + "block_type": "compute" + }, + "inputs": { + "prompt": { + "type": "Any", + "connections": [ + { + "block": "openai-agent-1-tuo6ndtm42rc", + "variable": "response" + } + ] + }, + "api_key": { + "type": "Any", + "connections": [ + { + "block": "password-cra270gb0hn0", + "variable": "password" + } + ] + } + }, + "outputs": { + "htlm": { + "type": "Any", + "connections": [ + { + "block": "view-html-8qh8d7kxxrph", + "variable": "html_path" + } + ] + }, + "content": { + "type": "Any", + "connections": [ + { + "block": "interface-maker-ool7kd5xa3sw", + "variable": "initial_content" + } + ] + } + }, + "action": { + "container": { + "image": "text-to-html-app", + "version": "text-to-html-app-rd6kt1w8j4zfy", + "command_line": [ + "python", + "entrypoint.py" + ] + } + }, + "views": { + "node": { + "active": "True", + "title_bar": {}, + "preview": {}, + "html": "", + "pos_x": "1330", + "pos_y": "414", + "pos_z": "999", + "behavior": "modal", + "order": { + "input": [ + "prompt", + "api_key" + ], + "output": [ + "htlm", + "content" + ] + } + } + }, + "events": {} +} \ No newline at end of file diff --git a/frontend/core/pipelines/pipeline-text-to-game/view-html-8qh8d7kxxrph/Dockerfile b/frontend/core/pipelines/pipeline-text-to-game/view-html-8qh8d7kxxrph/Dockerfile new file mode 100644 index 00000000..7f29ac11 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/view-html-8qh8d7kxxrph/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.9 + +WORKDIR /app + +COPY . . + +RUN pip install --no-cache-dir -r requirements.txt diff --git a/frontend/core/pipelines/pipeline-text-to-game/view-html-8qh8d7kxxrph/computations.py b/frontend/core/pipelines/pipeline-text-to-game/view-html-8qh8d7kxxrph/computations.py new file mode 100644 index 00000000..bea231d9 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/view-html-8qh8d7kxxrph/computations.py @@ -0,0 +1,28 @@ +import uuid + +def compute(html_path): + """Display the input HTML page. + + Inputs: + html_path: Path to the HTML file to be displayed. + + Outputs: + dict: A dictionary with the key 'html' and the value being the name of the generated HTML file. + """ + + # Load the HTML template + with open(html_path, 'r') as file: + html_content = file.read() + + # Write the file + unique_id = str(uuid.uuid4()) + html_path = f"/files/viz_{unique_id}.html" + + with open(html_path, "w") as file: + file.write(html_content) + + return {"html": f"viz_{unique_id}.html"} + +def test(): + """Test the compute function.""" + print("Running test") diff --git a/frontend/core/pipelines/pipeline-text-to-game/view-html-8qh8d7kxxrph/requirements.txt b/frontend/core/pipelines/pipeline-text-to-game/view-html-8qh8d7kxxrph/requirements.txt new file mode 100644 index 00000000..99a80913 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/view-html-8qh8d7kxxrph/requirements.txt @@ -0,0 +1,2 @@ + + diff --git a/frontend/core/pipelines/pipeline-text-to-game/view-html-8qh8d7kxxrph/specs.json b/frontend/core/pipelines/pipeline-text-to-game/view-html-8qh8d7kxxrph/specs.json new file mode 100644 index 00000000..cf0589c1 --- /dev/null +++ b/frontend/core/pipelines/pipeline-text-to-game/view-html-8qh8d7kxxrph/specs.json @@ -0,0 +1,65 @@ +{ + "information": { + "id": "view-html", + "name": "View HTML", + "description": "Display the input HTML page.\n\nInputs:\n html_path: Path to the HTML file to be displayed.\n\nOutputs:\n dict: A dictionary with the key 'html' and the value being the name of the generated HTML file.", + "system_versions": [ + "0.1" + ], + "block_version": "1.0", + "block_source": "core/blocks/view-html", + "block_type": "view" + }, + "inputs": { + "html_path": { + "type": "Any", + "connections": [ + { + "block": "text-to-html-app-r6kt1w8j4zfy", + "variable": "htlm" + } + ] + } + }, + "outputs": { + "html": { + "type": "Any", + "connections": [] + } + }, + "action": { + "container": { + "image": "view-html", + "version": "view-html-8qh8d7kxxrph", + "command_line": [ + "python", + "entrypoint.py" + ] + } + }, + "views": { + "node": { + "active": "true", + "title_bar": { + "background_color": "#0099ff" + }, + "preview": { + "active": "true" + }, + "html": "", + "pos_x": "1784", + "pos_y": "260", + "pos_z": "999", + "order": { + "input": [ + "html_path" + ], + "output": [ + "html" + ] + } + }, + "mode": "modal" + }, + "events": {} +} \ No newline at end of file