Spaces:
Running
Running
Banjo Obayomi
commited on
Commit
•
4e00891
1
Parent(s):
c88e6d6
add command-r plus
Browse files- .gitignore +1 -0
- app.py +65 -3
.gitignore
CHANGED
@@ -3,6 +3,7 @@ gradio_cached_examples/
|
|
3 |
static/*
|
4 |
static/
|
5 |
notes.txt
|
|
|
6 |
|
7 |
*.py[cod]
|
8 |
|
|
|
3 |
static/*
|
4 |
static/
|
5 |
notes.txt
|
6 |
+
test_model.py
|
7 |
|
8 |
*.py[cod]
|
9 |
|
app.py
CHANGED
@@ -257,6 +257,62 @@ def call_claude_3_haiku(system_prompt, prompt, temperature):
|
|
257 |
return results
|
258 |
|
259 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
system_prompt_text = """
|
261 |
As an esteemed level designer renowned for creating some of the top 100 levels in Super Mario Maker, you are tasked with crafting a playable section for the original Super Mario on NES. Your extensive experience and creativity are key to designing levels that are not only challenging but also immensely enjoyable. Use the following symbols to represent different game elements, ensuring each level is a masterpiece of design:
|
262 |
|
@@ -403,6 +459,10 @@ def generate(model, prompt, temperature, system_prompt=system_prompt_text):
|
|
403 |
level = call_llama3_8b(system_prompt, prompt, temperature)
|
404 |
elif model == "Claude Opus":
|
405 |
level = call_claude_3_opus(system_prompt, prompt, temperature)
|
|
|
|
|
|
|
|
|
406 |
else:
|
407 |
raise ValueError("Invalid model")
|
408 |
|
@@ -449,8 +509,8 @@ You can try it out by entering in a prompt and clicking `Generate level` to play
|
|
449 |
)
|
450 |
|
451 |
text_prompt = gr.Textbox(
|
452 |
-
value="Generate a level with a few pipes, many coins. make sure there are
|
453 |
-
label="Enter your MarioGPT prompt. ex: 'Generate a level with a few pipes, many coins. make sure there are
|
454 |
)
|
455 |
|
456 |
model = gr.Radio(
|
@@ -460,6 +520,8 @@ You can try it out by entering in a prompt and clicking `Generate level` to play
|
|
460 |
"Claude Haiku",
|
461 |
"Llama3 70B",
|
462 |
"Llama3 8B",
|
|
|
|
|
463 |
],
|
464 |
label="Select Model",
|
465 |
value="Claude Opus",
|
@@ -510,7 +572,7 @@ You can try it out by entering in a prompt and clicking `Generate level` to play
|
|
510 |
0.7,
|
511 |
],
|
512 |
[
|
513 |
-
"
|
514 |
"Make a simple level that has no enemies, but lots and lots of coins. Lots of blocks for Mario to walk on.",
|
515 |
0.7,
|
516 |
],
|
|
|
257 |
return results
|
258 |
|
259 |
|
260 |
+
def call_command_r_plus(system_prompt, prompt, temperature):
|
261 |
+
|
262 |
+
chat_history = [
|
263 |
+
{"role": "USER", "message": system_prompt},
|
264 |
+
]
|
265 |
+
|
266 |
+
prompt_config = {
|
267 |
+
"message": prompt,
|
268 |
+
"max_tokens": 4096,
|
269 |
+
"chat_history": chat_history,
|
270 |
+
"temperature": temperature,
|
271 |
+
}
|
272 |
+
|
273 |
+
body = json.dumps(prompt_config)
|
274 |
+
|
275 |
+
modelId = "cohere.command-r-plus-v1:0"
|
276 |
+
accept = "application/json"
|
277 |
+
contentType = "application/json"
|
278 |
+
|
279 |
+
response = bedrock_runtime.invoke_model(
|
280 |
+
body=body, modelId=modelId, accept=accept, contentType=contentType
|
281 |
+
)
|
282 |
+
response_body = json.loads(response.get("body").read())
|
283 |
+
|
284 |
+
results = response_body.get("text")
|
285 |
+
return results
|
286 |
+
|
287 |
+
|
288 |
+
def call_command_r(system_prompt, prompt, temperature):
|
289 |
+
|
290 |
+
chat_history = [
|
291 |
+
{"role": "USER", "message": system_prompt},
|
292 |
+
]
|
293 |
+
|
294 |
+
prompt_config = {
|
295 |
+
"message": prompt,
|
296 |
+
"max_tokens": 4096,
|
297 |
+
"chat_history": chat_history,
|
298 |
+
"temperature": temperature,
|
299 |
+
}
|
300 |
+
|
301 |
+
body = json.dumps(prompt_config)
|
302 |
+
|
303 |
+
modelId = "cohere.command-r-v1:0"
|
304 |
+
accept = "application/json"
|
305 |
+
contentType = "application/json"
|
306 |
+
|
307 |
+
response = bedrock_runtime.invoke_model(
|
308 |
+
body=body, modelId=modelId, accept=accept, contentType=contentType
|
309 |
+
)
|
310 |
+
response_body = json.loads(response.get("body").read())
|
311 |
+
|
312 |
+
results = response_body.get("text")
|
313 |
+
return results
|
314 |
+
|
315 |
+
|
316 |
system_prompt_text = """
|
317 |
As an esteemed level designer renowned for creating some of the top 100 levels in Super Mario Maker, you are tasked with crafting a playable section for the original Super Mario on NES. Your extensive experience and creativity are key to designing levels that are not only challenging but also immensely enjoyable. Use the following symbols to represent different game elements, ensuring each level is a masterpiece of design:
|
318 |
|
|
|
459 |
level = call_llama3_8b(system_prompt, prompt, temperature)
|
460 |
elif model == "Claude Opus":
|
461 |
level = call_claude_3_opus(system_prompt, prompt, temperature)
|
462 |
+
elif model == "Command R Plus":
|
463 |
+
level = call_command_r_plus(system_prompt, prompt, temperature)
|
464 |
+
elif model == "Command R":
|
465 |
+
level = call_command_r(system_prompt, prompt, temperature)
|
466 |
else:
|
467 |
raise ValueError("Invalid model")
|
468 |
|
|
|
509 |
)
|
510 |
|
511 |
text_prompt = gr.Textbox(
|
512 |
+
value="Generate a level with a few pipes, many coins. make sure there are around 10 enemies. Make sure there is a ground path Mario can walk on",
|
513 |
+
label="Enter your MarioGPT prompt. ex: 'Generate a level with a few pipes, many coins. make sure there are around 10 enemies. Make sure there is a ground path Mario can walk on'",
|
514 |
)
|
515 |
|
516 |
model = gr.Radio(
|
|
|
520 |
"Claude Haiku",
|
521 |
"Llama3 70B",
|
522 |
"Llama3 8B",
|
523 |
+
"Command R Plus",
|
524 |
+
# "Command R", # taking too long to generate
|
525 |
],
|
526 |
label="Select Model",
|
527 |
value="Claude Opus",
|
|
|
572 |
0.7,
|
573 |
],
|
574 |
[
|
575 |
+
"Command R Plus",
|
576 |
"Make a simple level that has no enemies, but lots and lots of coins. Lots of blocks for Mario to walk on.",
|
577 |
0.7,
|
578 |
],
|