mirror of
https://github.com/wassname/Clover-Edition.git
synced 2026-09-10 11:40:48 +08:00
added generate script
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
**/__pychache__
|
||||
.idea
|
||||
RL
|
||||
AI-Adventure*.json
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
END=20
|
||||
for ((I=0;I<END;I++));
|
||||
do
|
||||
python3 main.py "$(($I * 5))" "$(( ($I + 1) * 5 ))" &
|
||||
done
|
||||
Binary file not shown.
Binary file not shown.
@@ -25,6 +25,7 @@ from flask import Flask, render_template, request, abort
|
||||
from flask import Response
|
||||
import requests
|
||||
import pdb
|
||||
import sys
|
||||
import gpt2.src.encoder as encoder
|
||||
|
||||
|
||||
@@ -117,7 +118,7 @@ def about():
|
||||
|
||||
def cache_file(seed, prompt_num, choices, response, tag):
|
||||
|
||||
blob_file_name = "p" + str(prompt_num) + "/seed" + str(seed) + "/" + tag
|
||||
blob_file_name = "prompt" + str(prompt_num) + "/seed" + str(seed) + "/" + tag
|
||||
for action in choices:
|
||||
blob_file_name = blob_file_name + str(action)
|
||||
blob = bucket.blob(blob_file_name)
|
||||
@@ -128,7 +129,7 @@ def cache_file(seed, prompt_num, choices, response, tag):
|
||||
|
||||
|
||||
def retrieve_from_cache(seed, prompt_num, choices, tag):
|
||||
blob_file_name = "p" + str(prompt_num) + "/seed" + str(seed) + "/" + tag
|
||||
blob_file_name = "prompt" + str(prompt_num) + "/seed" + str(seed) + "/" + tag
|
||||
|
||||
for action in choices:
|
||||
blob_file_name = blob_file_name + str(action)
|
||||
@@ -189,22 +190,24 @@ def story_request():
|
||||
|
||||
def generate_cache():
|
||||
|
||||
start_seed = int(sys.argv[1])
|
||||
end_seed = int(sys.argv[2])
|
||||
|
||||
|
||||
# Generate story sections
|
||||
"""
|
||||
prompt_num = 0
|
||||
generator = StoryGenerator(tf.Session())
|
||||
for seed in range(100):
|
||||
action_queue = []
|
||||
prompt = prompts[prompt_num]
|
||||
for seed in range(start_seed,end_seed):
|
||||
result = retrieve_from_cache(seed, prompt_num, [], "story")
|
||||
if result is not None:
|
||||
response = result
|
||||
else:
|
||||
prompt = prompts[prompt_num]
|
||||
response = generator.generate_story_block(prompt)
|
||||
response = generate_story_block(prompt)
|
||||
cache_file(seed, prompt_num, [], response, "story")
|
||||
|
||||
"""
|
||||
action_queue = [[i, 0, []] for i in range(100)]
|
||||
action_queue.append([seed,0,[],prompt+response, ""])
|
||||
|
||||
while(True):
|
||||
|
||||
@@ -212,24 +215,30 @@ def generate_cache():
|
||||
seed = next_gen[0]
|
||||
prompt_num = next_gen[1]
|
||||
choices = next_gen[2]
|
||||
initial_prompt = next_gen[3]
|
||||
last_action_result = next_gen[4]
|
||||
|
||||
action_results = retrieve_from_cache(seed, prompt_num, choices, "choices")
|
||||
|
||||
if action_results is not None:
|
||||
response = action_results
|
||||
|
||||
else:
|
||||
action_results = [generate_action_result(prompt, phrase) for phrase in phrases]
|
||||
response = json.dumps(action_results)
|
||||
cache_file(seed, prompt_num, choices, response, "choices")
|
||||
|
||||
un_jsoned = json.loads(response)
|
||||
for j in range(4):
|
||||
new_choices = choices[:]
|
||||
new_choices.append(j)
|
||||
action_queue.append([seed, 0, new_choices])
|
||||
action_queue.append([seed, 0, new_choices, initial_prompt, un_jsoned[j]])
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
app.run(host='0.0.0.0', port=8080)
|
||||
if(len(sys.argv) > 1):
|
||||
generate_cache()
|
||||
else:
|
||||
app.run(host='0.0.0.0', port=8080)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user