Oranblock commited on
Commit
7bfc8b0
·
verified ·
1 Parent(s): ab1f532

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -88
app.py CHANGED
@@ -1,6 +1,6 @@
1
  import streamlit as st
2
  import json
3
- import requests
4
 
5
  def load_config():
6
  with open('config.json', 'r') as f:
@@ -285,94 +285,100 @@ def get_user_input(config):
285
  }
286
 
287
  def generate_lua_script(params, api_key):
288
- url = "https://api.groq.com/v1/lua_script" # Example URL, replace with actual API endpoint
289
- headers = {
290
- "Authorization": f"Bearer {api_key}",
291
- "Content-Type": "application/json"
292
- }
293
 
294
- if params["custom_prompt"]:
295
- prompt = params["custom_prompt"]
296
- else:
297
- prompt = "Create a Lua script for Roblox that:\n"
298
- if params["color"]:
299
- prompt += f"1. Creates a {params['shape']} with the specified color {params['color']}.\n"
300
- if params["size"]:
301
- prompt += f"2. Specifies the size {params['size']}.\n"
302
- if params["position"]:
303
- prompt += f"3. Positions it at {params['position']}.\n"
304
- if params["part_cframe"]:
305
- prompt += f"4. Sets its CFrame to {params['part_cframe']}.\n"
306
- if params["material"]:
307
- prompt += f"5. Sets the material to {params['material']}.\n"
308
- if params["transparency"]:
309
- prompt += f"6. Sets the transparency to {params['transparency']}.\n"
310
- if params["reflectance"]:
311
- prompt += f"7. Sets the reflectance to {params['reflectance']}.\n"
312
- if params["rotation_speed"]:
313
- prompt += f"8. Rotates the {params['shape']} at a speed of {params['rotation_speed']}.\n"
314
- if params["bounce_height"]:
315
- prompt += f"9. Sets the bounce height to {params['bounce_height']}.\n"
316
- if params["collision"]:
317
- prompt += f"10. Sets collision to {params['collision']}.\n"
318
- if params["surface"]:
319
- prompt += f"11. Sets the surface type to {params['surface']}.\n"
320
- if params["anchor"]:
321
- prompt += f"12. Sets anchor to {params['anchor']}.\n"
322
- if params["collision_group"]:
323
- prompt += f"13. Sets the collision group to {params['collision_group']}.\n"
324
- if params["angular_velocity"] and params["linear_velocity"]:
325
- prompt += f"14. Sets the angular velocity to {params['angular_velocity']} and linear velocity to {params['linear_velocity']}.\n"
326
- if params["density"]:
327
- prompt += f"15. Sets the density to {params['density']}.\n"
328
- if params["camera_type"]:
329
- prompt += f"16. Sets the camera type to {params['camera_type']}.\n"
330
- if params["camera_position"]:
331
- prompt += f"17. Sets the camera position to {params['camera_position']}.\n"
332
- if params["field_of_view"]:
333
- prompt += f"18. Sets the field of view to {params['field_of_view']}.\n"
334
- if params["camera_interpolation"]:
335
- prompt += f"19. Enables camera interpolation.\n"
336
- if params["ambient_light"]:
337
- prompt += f"20. Sets the ambient light to {params['ambient_light']}.\n"
338
- if params["brightness"]:
339
- prompt += f"21. Sets the brightness to {params['brightness']}.\n"
340
- if params["time_of_day"]:
341
- prompt += f"22. Sets the time of day to {params['time_of_day']}.\n"
342
- if params["shadow_softness"]:
343
- prompt += f"23. Sets the shadow softness to {params['shadow_softness']}.\n"
344
- if params["shadow_color"]:
345
- prompt += f"24. Sets the shadow color to {params['shadow_color']}.\n"
346
- if params["fog_start"] and params["fog_end"] and params["fog_color"]:
347
- prompt += f"25. Sets fog with start distance {params['fog_start']}, end distance {params['fog_end']}, and color {params['fog_color']}.\n"
348
- if params["walk_speed"]:
349
- prompt += f"26. Sets the player's walk speed to {params['walk_speed']}.\n"
350
- if params["jump_power"]:
351
- prompt += f"27. Sets the player's jump power to {params['jump_power']}.\n"
352
- if params["health"]:
353
- prompt += f"28. Sets the player's health to {params['health']}.\n"
354
- if params["respawn_time"]:
355
- prompt += f"29. Sets the respawn time to {params['respawn_time']}.\n"
356
- if params["background_music"]:
357
- prompt += f"30. Adds background music with ID {params['background_music']} and sets volume to {params['sound_volume']}.\n"
358
- if params["sound_effects"]:
359
- prompt += f"31. Adds sound effects with ID {params['sound_effects']}.\n"
360
- if params["environmental_sounds"]:
361
- prompt += f"32. Adds environmental sounds with ID {params['environmental_sounds']}.\n"
362
- if params["ui_text"]:
363
- prompt += f"33. Adds UI text '{params['ui_text']}' at position {params['ui_position']} with size {params['ui_size']} and color {params['ui_color']} using font {params['ui_font']} and text size {params['ui_text_size']}.\n"
364
- if params["texture_id"] and params["decal_position"]:
365
- prompt += f"34. Adds a decal with texture ID {params['texture_id']} at position {params['decal_position']}.\n"
366
- if params["particle_texture"]:
367
- prompt += f"35. Adds particle effects with texture ID {params['particle_texture']}, lifetime {params['particle_lifetime']}, rate {params['particle_rate']}, speed {params['particle_speed']}, size {params['particle_size']}, acceleration {params['particle_acceleration']}, rotation speed {params['particle_rot_speed']}, and color {params['particle_color']}.\n"
368
-
369
- data = {
370
- "prompt": prompt
371
- }
372
-
373
- response = requests.post(url, headers=headers, json=data)
374
- response.raise_for_status() # Raise an exception for HTTP errors
375
- return response.json()['script']
 
 
 
 
 
 
 
 
 
376
 
377
  def main():
378
  config = load_config()
 
1
  import streamlit as st
2
  import json
3
+ from groq import Groq
4
 
5
  def load_config():
6
  with open('config.json', 'r') as f:
 
285
  }
286
 
287
  def generate_lua_script(params, api_key):
288
+ client = Groq(api_key=api_key)
289
+ prompt = params["custom_prompt"] if params["custom_prompt"] else "Create a Lua script for Roblox that:\n"
 
 
 
290
 
291
+ if params["color"]:
292
+ prompt += f"1. Creates a {params['shape']} with the specified color {params['color']}.\n"
293
+ if params["size"]:
294
+ prompt += f"2. Specifies the size {params['size']}.\n"
295
+ if params["position"]:
296
+ prompt += f"3. Positions it at {params['position']}.\n"
297
+ if params["part_cframe"]:
298
+ prompt += f"4. Sets its CFrame to {params['part_cframe']}.\n"
299
+ if params["material"]:
300
+ prompt += f"5. Sets the material to {params['material']}.\n"
301
+ if params["transparency"]:
302
+ prompt += f"6. Sets the transparency to {params['transparency']}.\n"
303
+ if params["reflectance"]:
304
+ prompt += f"7. Sets the reflectance to {params['reflectance']}.\n"
305
+ if params["rotation_speed"]:
306
+ prompt += f"8. Rotates the {params['shape']} at a speed of {params['rotation_speed']}.\n"
307
+ if params["bounce_height"]:
308
+ prompt += f"9. Sets the bounce height to {params['bounce_height']}.\n"
309
+ if params["collision"]:
310
+ prompt += f"10. Sets collision to {params['collision']}.\n"
311
+ if params["surface"]:
312
+ prompt += f"11. Sets the surface type to {params['surface']}.\n"
313
+ if params["anchor"]:
314
+ prompt += f"12. Sets anchor to {params['anchor']}.\n"
315
+ if params["collision_group"]:
316
+ prompt += f"13. Sets the collision group to {params['collision_group']}.\n"
317
+ if params["angular_velocity"] and params["linear_velocity"]:
318
+ prompt += f"14. Sets the angular velocity to {params['angular_velocity']} and linear velocity to {params['linear_velocity']}.\n"
319
+ if params["density"]:
320
+ prompt += f"15. Sets the density to {params['density']}.\n"
321
+ if params["camera_type"]:
322
+ prompt += f"16. Sets the camera type to {params['camera_type']}.\n"
323
+ if params["camera_position"]:
324
+ prompt += f"17. Sets the camera position to {params['camera_position']}.\n"
325
+ if params["field_of_view"]:
326
+ prompt += f"18. Sets the field of view to {params['field_of_view']}.\n"
327
+ if params["camera_interpolation"]:
328
+ prompt += f"19. Enables camera interpolation.\n"
329
+ if params["ambient_light"]:
330
+ prompt += f"20. Sets the ambient light to {params['ambient_light']}.\n"
331
+ if params["brightness"]:
332
+ prompt += f"21. Sets the brightness to {params['brightness']}.\n"
333
+ if params["time_of_day"]:
334
+ prompt += f"22. Sets the time of day to {params['time_of_day']}.\n"
335
+ if params["shadow_softness"]:
336
+ prompt += f"23. Sets the shadow softness to {params['shadow_softness']}.\n"
337
+ if params["shadow_color"]:
338
+ prompt += f"24. Sets the shadow color to {params['shadow_color']}.\n"
339
+ if params["fog_start"] and params["fog_end"] and params["fog_color"]:
340
+ prompt += f"25. Sets fog with start distance {params['fog_start']}, end distance {params['fog_end']}, and color {params['fog_color']}.\n"
341
+ if params["walk_speed"]:
342
+ prompt += f"26. Sets the player's walk speed to {params['walk_speed']}.\n"
343
+ if params["jump_power"]:
344
+ prompt += f"27. Sets the player's jump power to {params['jump_power']}.\n"
345
+ if params["health"]:
346
+ prompt += f"28. Sets the player's health to {params['health']}.\n"
347
+ if params["respawn_time"]:
348
+ prompt += f"29. Sets the respawn time to {params['respawn_time']}.\n"
349
+ if params["background_music"]:
350
+ prompt += f"30. Adds background music with ID {params['background_music']} and sets volume to {params['sound_volume']}.\n"
351
+ if params["sound_effects"]:
352
+ prompt += f"31. Adds sound effects with ID {params['sound_effects']}.\n"
353
+ if params["environmental_sounds"]:
354
+ prompt += f"32. Adds environmental sounds with ID {params['environmental_sounds']}.\n"
355
+ if params["ui_text"]:
356
+ prompt += f"33. Adds UI text '{params['ui_text']}' at position {params['ui_position']} with size {params['ui_size']} and color {params['ui_color']} using font {params['ui_font']} and text size {params['ui_text_size']}.\n"
357
+ if params["texture_id"] and params["decal_position"]:
358
+ prompt += f"34. Adds a decal with texture ID {params['texture_id']} at position {params['decal_position']}.\n"
359
+ if params["particle_texture"]:
360
+ prompt += f"35. Adds particle effects with texture ID {params['particle_texture']}, lifetime {params['particle_lifetime']}, rate {params['particle_rate']}, speed {params['particle_speed']}, size {params['particle_size']}, acceleration {params['particle_acceleration']}, rotation speed {params['particle_rot_speed']}, and color {params['particle_color']}.\n"
361
+
362
+ completion = client.chat.completions.create(
363
+ model="llama3-8b-8192",
364
+ messages=[
365
+ {
366
+ "role": "user",
367
+ "content": prompt
368
+ }
369
+ ],
370
+ temperature=1,
371
+ max_tokens=1024,
372
+ top_p=1,
373
+ stream=True,
374
+ stop=None,
375
+ )
376
+
377
+ lua_script = ""
378
+ for chunk in completion:
379
+ lua_script += chunk.choices[0].delta.content or ""
380
+
381
+ return lua_script
382
 
383
  def main():
384
  config = load_config()