Skip to content

Commit

Permalink
Added option to import character data from character cards and json f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
Hukasx0 committed Nov 21, 2023
1 parent be7421a commit 4f2e192
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 0 deletions.
65 changes: 65 additions & 0 deletions app/main-mistral-webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,34 @@ def input_none(text):
"""## Start WebUI"""


def import_character_json(json_path):
print(json_path)
if json_path is not None:
character = aichar.load_character_json_file(json_path)
return (
character.name,
character.summary,
character.personality,
character.scenario,
character.greeting_message,
character.example_messages,
)


def import_character_card(card_path):
print(card_path)
if card_path is not None:
character = aichar.load_character_card_file(card_path)
return (
character.name,
character.summary,
character.personality,
character.scenario,
character.greeting_message,
character.example_messages,
)


def export_as_json(
name, summary, personality, scenario, greeting_message, example_messages
):
Expand Down Expand Up @@ -485,6 +513,43 @@ def export_character_card(
],
outputs=image_input,
)
with gr.Tab("Import character"):
with gr.Column():
with gr.Row():
import_card_input = gr.File(
label="Upload character card file", file_types=[".png"]
)
import_json_input = gr.File(
label="Upload JSON file", file_types=[".json"]
)
with gr.Row():
import_card_button = gr.Button("Import character from character card") # nopep8
import_json_button = gr.Button("Import character from json")

import_card_button.click(
import_character_card,
inputs=[import_card_input],
outputs=[
name,
summary,
personality,
scenario,
greeting_message,
example_messages,
],
)
import_json_button.click(
import_character_json,
inputs=[import_json_input],
outputs=[
name,
summary,
personality,
scenario,
greeting_message,
example_messages,
],
)
with gr.Tab("Export character"):
with gr.Column():
with gr.Row():
Expand Down
65 changes: 65 additions & 0 deletions app/main-zephyr-webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,34 @@ def input_none(text):
"""## Start WebUI"""


def import_character_json(json_path):
print(json_path)
if json_path is not None:
character = aichar.load_character_json_file(json_path)
return (
character.name,
character.summary,
character.personality,
character.scenario,
character.greeting_message,
character.example_messages,
)


def import_character_card(card_path):
print(card_path)
if card_path is not None:
character = aichar.load_character_card_file(card_path)
return (
character.name,
character.summary,
character.personality,
character.scenario,
character.greeting_message,
character.example_messages,
)


def export_as_json(
name, summary, personality, scenario, greeting_message, example_messages
):
Expand Down Expand Up @@ -556,6 +584,43 @@ def export_character_card(
],
outputs=image_input,
)
with gr.Tab("Import character"):
with gr.Column():
with gr.Row():
import_card_input = gr.File(
label="Upload character card file", file_types=[".png"]
)
import_json_input = gr.File(
label="Upload JSON file", file_types=[".json"]
)
with gr.Row():
import_card_button = gr.Button("Import character from character card") # nopep8
import_json_button = gr.Button("Import character from json")

import_card_button.click(
import_character_card,
inputs=[import_card_input],
outputs=[
name,
summary,
personality,
scenario,
greeting_message,
example_messages,
],
)
import_json_button.click(
import_character_json,
inputs=[import_json_input],
outputs=[
name,
summary,
personality,
scenario,
greeting_message,
example_messages,
],
)
with gr.Tab("Export character"):
with gr.Column():
with gr.Row():
Expand Down
25 changes: 25 additions & 0 deletions colab/character_factory_colab_mistral.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,18 @@
"import gradio as gr\n",
"from PIL import Image\n",
"\n",
"def import_character_json(json_path):\n",
" print(json_path)\n",
" if json_path is not None:\n",
" character = aichar.load_character_json_file(json_path)\n",
" return character.name, character.summary, character.personality, character.scenario, character.greeting_message, character.example_messages\n",
"\n",
"def import_character_card(card_path):\n",
" print(card_path)\n",
" if card_path is not None:\n",
" character = aichar.load_character_card_file(card_path)\n",
" return character.name, character.summary, character.personality, character.scenario, character.greeting_message, character.example_messages\n",
"\n",
"def export_as_json(name, summary, personality, scenario, greeting_message, example_messages):\n",
" character = aichar.create_character(\n",
" name=name,\n",
Expand Down Expand Up @@ -380,6 +392,19 @@
" avatar_button.click(generate_character_avatar,\n",
" inputs=[name, summary, topic, negative_prompt, avatar_prompt, potential_nsfw_checkbox],\n",
" outputs=image_input)\n",
"\n",
" with gr.Tab(\"Import character\"):\n",
" with gr.Column():\n",
" with gr.Row():\n",
" import_card_input = gr.File(label=\"Upload character card file\", file_types=[\".png\"])\n",
" import_json_input = gr.File(label=\"Upload JSON file\", file_types=[\".json\"])\n",
" with gr.Row():\n",
" import_card_button = gr.Button(\"Import character from character card\")\n",
" import_json_button = gr.Button(\"Import character from json\")\n",
"\n",
" import_card_button.click(import_character_card, inputs=[import_card_input], outputs=[name, summary, personality, scenario, greeting_message, example_messages])\n",
" import_json_button.click(import_character_json, inputs=[import_json_input], outputs=[name, summary, personality, scenario, greeting_message, example_messages])\n",
"\n",
" with gr.Tab(\"Export character\"):\n",
" with gr.Column():\n",
" with gr.Row():\n",
Expand Down
25 changes: 25 additions & 0 deletions colab/character_factory_colab_zephyr.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,18 @@
"import gradio as gr\n",
"from PIL import Image\n",
"\n",
"def import_character_json(json_path):\n",
" print(json_path)\n",
" if json_path is not None:\n",
" character = aichar.load_character_json_file(json_path)\n",
" return character.name, character.summary, character.personality, character.scenario, character.greeting_message, character.example_messages\n",
"\n",
"def import_character_card(card_path):\n",
" print(card_path)\n",
" if card_path is not None:\n",
" character = aichar.load_character_card_file(card_path)\n",
" return character.name, character.summary, character.personality, character.scenario, character.greeting_message, character.example_messages\n",
"\n",
"def export_as_json(name, summary, personality, scenario, greeting_message, example_messages):\n",
" character = aichar.create_character(\n",
" name=name,\n",
Expand Down Expand Up @@ -426,6 +438,19 @@
" avatar_button.click(generate_character_avatar,\n",
" inputs=[name, summary, topic, negative_prompt, avatar_prompt, potential_nsfw_checkbox],\n",
" outputs=image_input)\n",
"\n",
" with gr.Tab(\"Import character\"):\n",
" with gr.Column():\n",
" with gr.Row():\n",
" import_card_input = gr.File(label=\"Upload character card file\", file_types=[\".png\"])\n",
" import_json_input = gr.File(label=\"Upload JSON file\", file_types=[\".json\"])\n",
" with gr.Row():\n",
" import_card_button = gr.Button(\"Import character from character card\")\n",
" import_json_button = gr.Button(\"Import character from json\")\n",
"\n",
" import_card_button.click(import_character_card, inputs=[import_card_input], outputs=[name, summary, personality, scenario, greeting_message, example_messages])\n",
" import_json_button.click(import_character_json, inputs=[import_json_input], outputs=[name, summary, personality, scenario, greeting_message, example_messages])\n",
"\n",
" with gr.Tab(\"Export character\"):\n",
" with gr.Column():\n",
" with gr.Row():\n",
Expand Down

0 comments on commit 4f2e192

Please sign in to comment.