CoolFace
Apppublic

Oranblock/Lua_create

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py321 linesDownload Raw Back to root
1import streamlit as st2import json3from groq import Groq4 5def load_config():6    with open('config.json', 'r') as f:7        return json.load(f)8 9def checkbox_with_default(label, value, key):10    return st.checkbox(label, value=value, key=key)11 12def text_input_with_default(label, value, key):13    return st.text_input(label, value=value, key=key)14 15def selectbox_with_default(label, options, value, key):16    return st.selectbox(label, options, index=options.index(value), key=key)17 18def get_user_input(config):19    st.title("Advanced Roblox Lua Script Generator")20 21    default_params = config["default_parameters"]22 23    # Game Object Properties24    color_enabled = checkbox_with_default("Enable Color", True, "color_enabled")25    size_enabled = checkbox_with_default("Enable Size", True, "size_enabled")26    position_enabled = checkbox_with_default("Enable Position", True, "position_enabled")27    shape_enabled = checkbox_with_default("Enable Shape", True, "shape_enabled")28    material_enabled = checkbox_with_default("Enable Material", True, "material_enabled")29    transparency_enabled = checkbox_with_default("Enable Transparency", True, "transparency_enabled")30    reflectance_enabled = checkbox_with_default("Enable Reflectance", True, "reflectance_enabled")31    rotation_speed_enabled = checkbox_with_default("Enable Rotation Speed", True, "rotation_speed_enabled")32    bounce_height_enabled = checkbox_with_default("Enable Bounce Height", True, "bounce_height_enabled")33    collision_enabled = checkbox_with_default("Enable Collision", True, "collision_enabled")34    surface_enabled = checkbox_with_default("Enable Surface Type", True, "surface_enabled")35    anchor_enabled = checkbox_with_default("Enable Anchor", True, "anchor_enabled")36    collision_group_enabled = checkbox_with_default("Enable Collision Group", True, "collision_group_enabled")37    custom_physics_enabled = checkbox_with_default("Enable Custom Physics", True, "custom_physics_enabled")38    part_cframe_enabled = checkbox_with_default("Enable Part CFrame", True, "part_cframe_enabled")39 40    # Camera Properties41    camera_enabled = checkbox_with_default("Enable Camera Configuration", True, "camera_enabled")42    camera_interpolation_enabled = checkbox_with_default("Enable Camera Interpolation", default_params["camera_interpolation"], "camera_interpolation_enabled")43 44    # Lighting Properties45    lighting_enabled = checkbox_with_default("Enable Lighting Configuration", True, "lighting_enabled")46    fog_enabled = checkbox_with_default("Enable Environmental Fog", True, "fog_enabled")47    shadow_enabled = checkbox_with_default("Enable Shadow Properties", True, "shadow_enabled")48 49    # Player Properties50    player_settings_enabled = checkbox_with_default("Enable Player Settings", True, "player_settings_enabled")51    respawn_time_enabled = checkbox_with_default("Enable Respawn Time", True, "respawn_time_enabled")52 53    # Sound Properties54    sound_enabled = checkbox_with_default("Enable Sound", True, "sound_enabled")55    sound_effects_enabled = checkbox_with_default("Enable Sound Effects", True, "sound_effects_enabled")56    environmental_sounds_enabled = checkbox_with_default("Enable Environmental Sounds", True, "environmental_sounds_enabled")57 58    # UI Properties59    ui_enabled = checkbox_with_default("Enable UI Configuration", True, "ui_enabled")60 61    # Decals62    decals_enabled = checkbox_with_default("Enable Decals", True, "decals_enabled")63 64    # Particle Effects65    particles_enabled = checkbox_with_default("Enable Particle Effects", True, "particles_enabled")66 67    # Advanced Game Object Properties Inputs68    if color_enabled:69        color = text_input_with_default("Enter Color (RGB, e.g., 255,0,0)", default_params["color"], "color")70    else:71        color = None72 73    if size_enabled:74        size = text_input_with_default("Enter Size (X,Y,Z, e.g., 4,1,2)", default_params["size"], "size")75    else:76        size = None77 78    if position_enabled:79        position = text_input_with_default("Enter Position (X,Y,Z, e.g., 0,10,0)", default_params["position"], "position")80    else:81        position = None82 83    if shape_enabled:84        shape = selectbox_with_default("Select Shape", config["shapes"], default_params["shape"], "shape")85    else:86        shape = None87 88    if material_enabled:89        material = selectbox_with_default("Select Material", config["materials"], default_params["material"], "material")90    else:91        material = None92 93    if transparency_enabled:94        transparency = text_input_with_default("Enter Transparency (0-1, e.g., 0.5)", default_params["transparency"], "transparency")95    else:96        transparency = None97 98    if reflectance_enabled:99        reflectance = text_input_with_default("Enter Reflectance (0-1, e.g., 0.5)", default_params["reflectance"], "reflectance")100    else:101        reflectance = None102 103    if rotation_speed_enabled:104        rotation_speed = text_input_with_default("Enter Rotation Speed (e.g., 10)", default_params["rotation_speed"], "rotation_speed")105    else:106        rotation_speed = None107 108    if bounce_height_enabled:109        bounce_height = text_input_with_default("Enter Bounce Height (e.g., 10)", default_params["bounce_height"], "bounce_height")110    else:111        bounce_height = None112 113    if collision_enabled:114        collision = selectbox_with_default("Enable Collision", config["collisions"], default_params["collision"], "collision")115    else:116        collision = None117 118    if surface_enabled:119        surface = selectbox_with_default("Select Surface Type", config["surfaces"], default_params["surface"], "surface")120    else:121        surface = None122 123    if anchor_enabled:124        anchor = selectbox_with_default("Enable Anchor", ["true", "false"], default_params["anchor"], "anchor")125    else:126        anchor = None127 128    if collision_group_enabled:129        collision_group = selectbox_with_default("Select Collision Group", config["collision_groups"], default_params["collision_group"], "collision_group")130    else:131        collision_group = None132 133    if custom_physics_enabled:134        angular_velocity = text_input_with_default("Enter Angular Velocity (X,Y,Z, e.g., 0,0,0)", default_params["angular_velocity"], "angular_velocity")135        linear_velocity = text_input_with_default("Enter Linear Velocity (X,Y,Z, e.g., 0,0,0)", default_params["linear_velocity"], "linear_velocity")136        density = text_input_with_default("Enter Density", default_params["density"], "density")137    else:138        angular_velocity = None139        linear_velocity = None140        density = None141 142    if part_cframe_enabled:143        part_cframe = text_input_with_default("Enter Part CFrame (e.g., CFrame.new(0, 50, -100))", default_params["part_cframe"], "part_cframe")144    else:145        part_cframe = None146 147    # Camera Properties Inputs148    if camera_enabled:149        camera_type = selectbox_with_default("Select Camera Type", config["camera_types"], default_params["camera_type"], "camera_type")150        camera_position = text_input_with_default("Enter Camera Position (X,Y,Z, e.g., 0,50,-100)", default_params["camera_position"], "camera_position")151        field_of_view = text_input_with_default("Enter Field of View", default_params["field_of_view"], "field_of_view")152    else:153        camera_type = None154        camera_position = None155        field_of_view = None156 157    if camera_interpolation_enabled:158        camera_interpolation = checkbox_with_default("Enable Camera Interpolation", default_params["camera_interpolation"], "camera_interpolation")159    else:160        camera_interpolation = None161 162    # Lighting Properties Inputs163    if lighting_enabled:164        ambient_light = text_input_with_default("Enter Ambient Light (RGB, e.g., 128,128,128)", default_params["ambient_light"], "ambient_light")165        brightness = text_input_with_default("Enter Brightness", default_params["brightness"], "brightness")166        time_of_day = selectbox_with_default("Select Time of Day", config["times_of_day"], default_params["time_of_day"], "time_of_day")167        shadow_softness = text_input_with_default("Enter Shadow Softness (0-1, e.g., 0.5)", default_params["shadow_softness"], "shadow_softness")168        shadow_color = text_input_with_default("Enter Shadow Color (RGB, e.g., 0,0,0)", default_params["shadow_color"], "shadow_color")169    else:170        ambient_light = None171        brightness = None172        time_of_day = None173        shadow_softness = None174        shadow_color = None175 176    if fog_enabled:177        fog_start = text_input_with_default("Enter Fog Start Distance", default_params["fog_start"], "fog_start")178        fog_end = text_input_with_default("Enter Fog End Distance", default_params["fog_end"], "fog_end")179        fog_color = text_input_with_default("Enter Fog Color (RGB, e.g., 128,128,128)", default_params["fog_color"], "fog_color")180    else:181        fog_start = None182        fog_end = None183        fog_color = None184 185    # Player Properties Inputs186    if player_settings_enabled:187        walk_speed = text_input_with_default("Enter Walk Speed", default_params["walk_speed"], "walk_speed")188        jump_power = text_input_with_default("Enter Jump Power", default_params["jump_power"], "jump_power")189        health = text_input_with_default("Enter Health", default_params["health"], "health")190    else:191        walk_speed = None192        jump_power = None193        health = None194 195    if respawn_time_enabled:196        respawn_time = text_input_with_default("Enter Respawn Time", default_params["respawn_time"], "respawn_time")197    else:198        respawn_time = None199 200    # Sound Properties Inputs201    if sound_enabled:202        background_music = text_input_with_default("Enter Background Music ID (e.g., rbxassetid://123456789)", default_params["background_music"], "background_music")203        sound_volume = text_input_with_default("Enter Sound Volume (e.g., 1)", default_params["sound_volume"], "sound_volume")204    else:205        background_music = None206        sound_volume = None207 208    if sound_effects_enabled:209        sound_effects = text_input_with_default("Enter Sound Effects ID (e.g., rbxassetid://987654321)", default_params["sound_effects"], "sound_effects")210    else:211        sound_effects = None212 213    if environmental_sounds_enabled:214        environmental_sounds = text_input_with_default("Enter Environmental Sounds ID (e.g., rbxassetid://1122334455)", default_params["environmental_sounds"], "environmental_sounds")215    else:216        environmental_sounds = None217 218    # UI Properties Inputs219    if ui_enabled:220        ui_text = text_input_with_default("Enter UI Text", default_params["ui_text"], "ui_text")221        ui_position = text_input_with_default("Enter UI Position (X,Y,Z, e.g., 0.5,-100,0.5,-25)", default_params["ui_position"], "ui_position")222        ui_size = text_input_with_default("Enter UI Size (X,Y,Z, e.g., 0,200,0,50)", default_params["ui_size"], "ui_size")223        ui_color = text_input_with_default("Enter UI Color (RGB, e.g., 255,255,255)", default_params["ui_color"], "ui_color")224        ui_font = selectbox_with_default("Select UI Font", config["fonts"], default_params["ui_font"], "ui_font")225        ui_text_size = text_input_with_default("Enter UI Text Size", default_params["ui_text_size"], "ui_text_size")226    else:227        ui_text = None228        ui_position = None229        ui_size = None230        ui_color = None231        ui_font = None232        ui_text_size = None233 234    # Decals Inputs235    if decals_enabled:236        texture_id = text_input_with_default("Enter Texture ID (e.g., rbxassetid://123456789)", default_params["texture_id"], "texture_id")237        decal_position = selectbox_with_default("Select Decal Position", config["decal_positions"], default_params["decal_position"], "decal_position")238    else:239        texture_id = None240        decal_position = None241 242    # Particle Effects Inputs243    if particles_enabled:244        particle_texture = text_input_with_default("Enter Particle Texture ID (e.g., rbxassetid://123456789)", default_params["particle_texture"], "particle_texture")245        particle_lifetime = text_input_with_default("Enter Particle Lifetime (e.g., 1,2)", default_params["particle_lifetime"], "particle_lifetime")246        particle_rate = text_input_with_default("Enter Particle Rate (e.g., 100)", default_params["particle_rate"], "particle_rate")247        particle_speed = text_input_with_default("Enter Particle Speed (e.g., 10,20)", default_params["particle_speed"], "particle_speed")248        particle_size = text_input_with_default("Enter Particle Size (e.g., 1,2)", default_params["particle_size"], "particle_size")249        particle_acceleration = text_input_with_default("Enter Particle Acceleration (X,Y,Z, e.g., 0,-10,0)", default_params["particle_acceleration"], "particle_acceleration")250        particle_rot_speed = text_input_with_default("Enter Particle Rotation Speed (e.g., 100,200)", default_params["particle_rot_speed"], "particle_rot_speed")251        particle_color = text_input_with_default("Enter Particle Color (RGB, e.g., 255,255,255)", default_params["particle_color"], "particle_color")252    else:253        particle_texture = None254        particle_lifetime = None255        particle_rate = None256        particle_speed = None257        particle_size = None258        particle_acceleration = None259        particle_rot_speed = None260        particle_color = None261 262    custom_prompt_enabled = checkbox_with_default("Enable Custom Prompt", False, "custom_prompt_enabled")263 264    custom_prompt = st.text_area("Enter Custom Prompt", "Create a Lua script for Roblox:", key="custom_prompt")265 266    return {267        "color": color, "size": size, "position": position, "shape": shape, "material": material,268        "transparency": transparency, "reflectance": reflectance, "rotation_speed": rotation_speed,269        "bounce_height": bounce_height, "collision": collision, "surface": surface, "anchor": anchor,270        "collision_group": collision_group, "angular_velocity": angular_velocity, "linear_velocity": linear_velocity,271        "density": density, "part_cframe": part_cframe, "camera_type": camera_type, "camera_position": camera_position,272        "field_of_view": field_of_view, "camera_interpolation": camera_interpolation, "ambient_light": ambient_light,273        "brightness": brightness, "time_of_day": time_of_day, "shadow_softness": shadow_softness, "shadow_color": shadow_color,274        "fog_start": fog_start, "fog_end": fog_end, "fog_color": fog_color, "walk_speed": walk_speed, "jump_power": jump_power,275        "health": health, "respawn_time": respawn_time, "background_music": background_music, "sound_volume": sound_volume,276        "sound_effects": sound_effects, "environmental_sounds": environmental_sounds, "ui_text": ui_text, "ui_position": ui_position,277        "ui_size": ui_size, "ui_color": ui_color, "ui_font": ui_font, "ui_text_size": ui_text_size, "texture_id": texture_id,278        "decal_position": decal_position, "particle_texture": particle_texture, "particle_lifetime": particle_lifetime,279        "particle_rate": particle_rate, "particle_speed": particle_speed, "particle_size": particle_size, 280        "particle_acceleration": particle_acceleration, "particle_rot_speed": particle_rot_speed, "particle_color": particle_color,281        "custom_prompt": custom_prompt282    }283 284def generate_lua_script(params, api_key):285    client = Groq(api_key=api_key)286    prompt = params["custom_prompt"]287    288    completion = client.chat.completions.create(289        model="llama3-8b-8192",290        messages=[291            {292                "role": "user",293                "content": prompt294            }295        ],296        temperature=1,297        max_tokens=1024,298        top_p=1,299        stream=True,300        stop=None,301    )302 303    lua_script = ""304    for chunk in completion:305        lua_script += chunk.choices[0].delta.content or ""306 307    return lua_script308 309def main():310    config = load_config()311    user_input = get_user_input(config)312 313    if st.button("Generate Script"):314        api_key = config["api_key"]315        lua_script = generate_lua_script(user_input, api_key)316        st.code(lua_script, language='lua')317        st.download_button(label="Copy to Clipboard", data=lua_script, file_name="lua_script.txt", mime="text/plain")318 319if __name__ == "__main__":320    main()321