Download core_creator/code_generator.py from mgbam/robosage: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/mgbam/robosage/resolve/a7d99477e66e61256f5430d2c184e879af5eb3d4/core_creator/code_generator.py
- Command line
-
hf download hf://spaces/mgbam/robosage@a7d99477e66e61256f5430d2c184e879af5eb3d4/core_creator/code_generator.py
-
curl -L -o code_generator.py https://huggingface.co/spaces/mgbam/robosage/resolve/a7d99477e66e61256f5430d2c184e879af5eb3d4/core_creator/code_generator.py
1.72 kB
| # code_generator.py - Turns app blueprint into executable Python code using OpenAI | |
| from openai import OpenAI | |
| import json | |
| def generate_app_code(blueprint: dict) -> str: | |
| base_prompt = f""" | |
| You are an expert Python developer and Gradio engineer. | |
| Generate a Hugging Face-ready app that does the following: | |
| Title: {blueprint.get("title")} | |
| Description: {blueprint.get("description")} | |
| Inputs: {blueprint.get("inputs")} | |
| Outputs: {blueprint.get("outputs")} | |
| Voice Commands: {blueprint.get("voice_commands")} | |
| Requirements: | |
| - Use Gradio Blocks. | |
| - Accept user voice or text input. | |
| - Use placeholder code for hardware control (e.g., robot.move_arm()). | |
| - Print logs for each user command detected. | |
| - Keep it in a single Python file. | |
| - Wrap robot behavior in a function named `robot_behavior()`. | |
| - Return only the Python code, no extra explanation. | |
| """ | |
| response = OpenAI().chat.completions.create( | |
| model="gpt-4o", | |
| messages=[ | |
| {"role": "system", "content": "You write production-quality Hugging Face Spaces code."}, | |
| {"role": "user", "content": base_prompt}, | |
| ], | |
| temperature=0.3 | |
| ) | |
| return response.choices[0].message.content.strip() | |
| # Example | |
| if __name__ == "__main__": | |
| sample_blueprint = { | |
| "title": "WaveBot", | |
| "description": "A robot that waves and greets customers.", | |
| "inputs": ["camera", "microphone"], | |
| "outputs": ["arm wave", "voice greeting"], | |
| "voice_commands": ["hello", "hi", "good morning"], | |
| "monetization": ["Retail subscription", "Affiliate for motion sensors"] | |
| } | |
| code = generate_app_code(sample_blueprint) | |
| print(code[:1000]) | |