Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More functions in webui, interface is more adapted to mobile #106

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion webui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

app = Flask(__name__)
app.static_folder = 'static'
app.config['TEMPLATES_AUTO_RELOAD'] = True
generate_lock = Lock()
session: Session

Expand Down Expand Up @@ -45,7 +46,7 @@ def api_edit_block():
@app.route("/api/delete_block", methods=['POST'])
def api_delete_block():
global session
data = request.get_json()
data = request.get_json()['uuid']
session.api_delete_block(data)
return json.dumps({"result": "ok"}) + "\n"

Expand Down Expand Up @@ -117,6 +118,21 @@ def api_userinput():
with generate_lock:
result = Response(stream_with_context(session.respond_multi(user_input)), mimetype = 'application/json')
return result

@app.route("/api/continue_gen", methods=['POST'])
def api_continue_gen():
with generate_lock:
result = Response(stream_with_context(session.respond_multi('')), mimetype = 'application/json')
return result

@app.route("/api/regen_block", methods=['POST'])
def api_regen():
global session
uuid = request.get_json()['uuid'];

with generate_lock:
result = Response(stream_with_context(session.regen_at(uuid)), mimetype = 'application/json')
return result

@app.route("/api/append_block", methods=['POST'])
def api_append_block():
Expand Down
25 changes: 21 additions & 4 deletions webui/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

sessions_dir: str

def get_generator():
global generator
return generator

def _sessions_dir(filename = None):
global sessions_dir

Expand Down Expand Up @@ -183,6 +187,9 @@ def __init__(self, filename, load):

self.max_response_tokens = saved.get("max_response_tokens", 512)
self.chunk_size = saved.get("chunk_size", 128)
self.format_use_italic = saved.get("format_use_italic", False)
self.format_use_bold = saved.get("format_use_bold", False)
self.session_color = saved.get("session_color", '#383848')

# Save new session

Expand All @@ -205,6 +212,9 @@ def save(self):
"break_on_newline": self.break_on_newline,
"max_response_tokens": self.max_response_tokens,
"chunk_size": self.chunk_size,
"format_use_italic": self.format_use_italic,
"format_use_bold": self.format_use_bold,
"session_color": self.session_color,
"token_repetition_penalty_max": generator.settings.token_repetition_penalty_max,
"token_repetition_penalty_sustain": generator.settings.token_repetition_penalty_sustain,
"token_repetition_penalty_decay": generator.settings.token_repetition_penalty_decay}
Expand Down Expand Up @@ -295,6 +305,9 @@ def api_populate(self):
"break_on_newline": self.break_on_newline,
"max_response_tokens": self.max_response_tokens,
"chunk_size": self.chunk_size,
"format_use_italic": self.format_use_italic,
"format_use_bold": self.format_use_bold,
"session_color": self.session_color,
"token_repetition_penalty_max": generator.settings.token_repetition_penalty_max,
"token_repetition_penalty_sustain": generator.settings.token_repetition_penalty_sustain,
"token_repetition_penalty_decay": generator.settings.token_repetition_penalty_decay,
Expand All @@ -311,16 +324,15 @@ def api_populate(self):
return json_object + "\n"


def api_delete_block(self, data):
def api_delete_block(self, block_id):

block_id = data["uuid"]
idx = -1
for i in range(len(self.history)):
if self.history[i].uuid == block_id:
idx = i
if idx == -1: return

self.history.pop(idx)
self.history = self.history[0:idx]
self.first_history_idx = 0
self.save()

Expand Down Expand Up @@ -379,6 +391,9 @@ def api_set_gen_settings(self, data):
generator.settings.token_repetition_penalty_max = data["token_repetition_penalty_max"]
generator.settings.token_repetition_penalty_sustain = data["token_repetition_penalty_sustain"]
generator.settings.token_repetition_penalty_decay = data["token_repetition_penalty_decay"]
self.format_use_italic = data["format_use_italic"]
self.format_use_bold = data["format_use_bold"]
self.session_color = data["session_color"]

self.save()

Expand Down Expand Up @@ -700,4 +715,6 @@ def respond_multi(self, user_input):

self.save()


def regen_at(self, uuid):
self.api_delete_block(uuid)
return self.respond_multi('')
Loading