Update app.py
Browse files
app.py
CHANGED
|
@@ -20,7 +20,7 @@ def get_top_chunks(query):
|
|
| 20 |
|
| 21 |
client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.2")
|
| 22 |
|
| 23 |
-
def respond(message, history, name,
|
| 24 |
response = ""
|
| 25 |
top_chunks = get_top_chunks(message)
|
| 26 |
context = "\n".join(top_chunks)
|
|
@@ -30,7 +30,7 @@ def respond(message, history, name, character_type):
|
|
| 30 |
"role": "system",
|
| 31 |
"content": (
|
| 32 |
f"You are a chatbot that helps users create characters for role-playing games."
|
| 33 |
-
f"The user
|
| 34 |
f"Use the following knowledge to inform your answers:\n\n{context}\n\n"
|
| 35 |
"Keep your answers under 300 words."
|
| 36 |
)
|
|
@@ -57,6 +57,12 @@ def respond(message, history, name, character_type):
|
|
| 57 |
|
| 58 |
# === GUI ===
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
with gr.Blocks() as chatbot:
|
| 61 |
with gr.Row(scale=1):
|
| 62 |
with gr.Column(scale=1):
|
|
@@ -67,12 +73,13 @@ with gr.Blocks() as chatbot:
|
|
| 67 |
show_download_button=False
|
| 68 |
)
|
| 69 |
with gr.Column(scale=1):
|
| 70 |
-
character_name = gr.Textbox(placeholder="Type your name here…")
|
| 71 |
-
|
|
|
|
| 72 |
|
| 73 |
gr.ChatInterface(
|
| 74 |
fn=respond,
|
| 75 |
-
additional_inputs=[character_name,
|
| 76 |
type="messages",
|
| 77 |
examples=None,
|
| 78 |
title="Character Creator",
|
|
|
|
| 20 |
|
| 21 |
client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.2")
|
| 22 |
|
| 23 |
+
def respond(message, history, name, char_class, char_alignemnt):
|
| 24 |
response = ""
|
| 25 |
top_chunks = get_top_chunks(message)
|
| 26 |
context = "\n".join(top_chunks)
|
|
|
|
| 30 |
"role": "system",
|
| 31 |
"content": (
|
| 32 |
f"You are a chatbot that helps users create characters for role-playing games."
|
| 33 |
+
f"The user might also provide the following information, please include their inputs in your response: \n Character name: {name}, Character Class: {char_class}, Character Alignment: {char_alignment}"
|
| 34 |
f"Use the following knowledge to inform your answers:\n\n{context}\n\n"
|
| 35 |
"Keep your answers under 300 words."
|
| 36 |
)
|
|
|
|
| 57 |
|
| 58 |
# === GUI ===
|
| 59 |
|
| 60 |
+
alignment_css="""
|
| 61 |
+
#alignment_radio{
|
| 62 |
+
color: blue;
|
| 63 |
+
}
|
| 64 |
+
"""
|
| 65 |
+
|
| 66 |
with gr.Blocks() as chatbot:
|
| 67 |
with gr.Row(scale=1):
|
| 68 |
with gr.Column(scale=1):
|
|
|
|
| 73 |
show_download_button=False
|
| 74 |
)
|
| 75 |
with gr.Column(scale=1):
|
| 76 |
+
character_name = gr.Textbox(label = "Character Name", placeholder="Type your name here…", info ="optional")
|
| 77 |
+
character_class = gr.CheckboxGroup(['Barbarian', 'Bard', 'Cleric', 'Druid', 'Fighter', 'Monk', 'Paladin', 'Ranger', 'Rogue', 'Sorcerer', 'Warlock', 'Wizard'], label="Character Class", info="Choose one or more")
|
| 78 |
+
character_alignment = gr.Radio(["Lawful Good", "Neutral Good", "Chaotic Good", "Lawful Neutral", "True Neutral", "Chaotic Neutral", "Lawful Evil", "Neutral Evil", "Chaotic Evil"], css=alignment_css, elem_id="alignment_radio")
|
| 79 |
|
| 80 |
gr.ChatInterface(
|
| 81 |
fn=respond,
|
| 82 |
+
additional_inputs=[character_name, character_class, character_alignment], # Pass name into function!
|
| 83 |
type="messages",
|
| 84 |
examples=None,
|
| 85 |
title="Character Creator",
|