Update app.py
Browse files
app.py
CHANGED
|
@@ -3,13 +3,20 @@ from huggingface_hub import InferenceClient
|
|
| 3 |
from sentence_transformers import SentenceTransformer
|
| 4 |
import torch
|
| 5 |
|
|
|
|
|
|
|
| 6 |
# Load knowledge
|
| 7 |
-
with open(
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 12 |
-
chunk_embeddings = model.encode(cleaned_chunks, convert_to_tensor=True)
|
| 13 |
|
| 14 |
def get_top_chunks(query):
|
| 15 |
query_embedding = model.encode(query, convert_to_tensor=True)
|
|
@@ -93,15 +100,16 @@ with gr.Blocks(theme=theme) as chatbot:
|
|
| 93 |
|
| 94 |
|
| 95 |
character_name = gr.Textbox(label = "Character Name", placeholder="Type your name here…", info ="optional")
|
| 96 |
-
character_class = gr.Dropdown(['Barbarian', 'Bard', 'Cleric', 'Druid', 'Fighter', 'Monk', 'Paladin', 'Ranger', 'Rogue', 'Sorcerer', 'Warlock', 'Wizard'], label="Character Class",
|
| 97 |
character_race = gr.Dropdown([
|
| 98 |
"Aarakocra", "Aasimar", "Bugbear", "Centaur", "Changeling", "Dragonborn", "Dwarf", "Elf",
|
| 99 |
"Fairy", "Firbolg", "Genasi", "Githyanki", "Githzerai", "Gnome", "Goblin", "Goliath",
|
| 100 |
"Half-Elf", "Half-Orc", "Halfling", "Hobgoblin", "Human", "Kenku", "Kobold", "Leonin",
|
| 101 |
"Lizardfolk", "Minotaur", "Orc", "Owlin", "Satyr", "Shadar-kai", "Shifter", "Tabaxi",
|
| 102 |
"Tiefling", "Tortle", "Triton", "Warforged", "Yuan-ti"
|
| 103 |
-
], multiselect=True, label="Character Race"
|
| 104 |
character_alignment = gr.Dropdown(["Lawful Good", "Neutral Good", "Chaotic Good", "Lawful Neutral", "True Neutral", "Chaotic Neutral", "Lawful Evil", "Neutral Evil", "Chaotic Evil"], label="Character Alignment", elem_classes="alignment_radio")
|
|
|
|
| 105 |
|
| 106 |
|
| 107 |
with gr.Column(scale=2):
|
|
|
|
| 3 |
from sentence_transformers import SentenceTransformer
|
| 4 |
import torch
|
| 5 |
|
| 6 |
+
def read_knowlege_file(knowlege_file)
|
| 7 |
+
|
| 8 |
# Load knowledge
|
| 9 |
+
with open(knowlege_file, "r", encoding="utf-8") as file:
|
| 10 |
+
knowledge = file.read()
|
| 11 |
+
|
| 12 |
+
cleaned_chunks = [chunk.strip() for chunk in knowledge.strip().split("\n") if chunk.strip()]
|
| 13 |
+
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 14 |
+
chunk_embeddings = model.encode(cleaned_chunks, convert_to_tensor=True)
|
| 15 |
+
return chunk_embeddings
|
| 16 |
+
|
| 17 |
+
chunk_embeddings = read_knowlege_file("knowlege.txt")
|
| 18 |
|
| 19 |
+
print(chunk_embeddings)
|
|
|
|
|
|
|
| 20 |
|
| 21 |
def get_top_chunks(query):
|
| 22 |
query_embedding = model.encode(query, convert_to_tensor=True)
|
|
|
|
| 100 |
|
| 101 |
|
| 102 |
character_name = gr.Textbox(label = "Character Name", placeholder="Type your name here…", info ="optional")
|
| 103 |
+
character_class = gr.Dropdown(['Barbarian', 'Bard', 'Cleric', 'Druid', 'Fighter', 'Monk', 'Paladin', 'Ranger', 'Rogue', 'Sorcerer', 'Warlock', 'Wizard'], label="Character Class", multiselect=True)
|
| 104 |
character_race = gr.Dropdown([
|
| 105 |
"Aarakocra", "Aasimar", "Bugbear", "Centaur", "Changeling", "Dragonborn", "Dwarf", "Elf",
|
| 106 |
"Fairy", "Firbolg", "Genasi", "Githyanki", "Githzerai", "Gnome", "Goblin", "Goliath",
|
| 107 |
"Half-Elf", "Half-Orc", "Halfling", "Hobgoblin", "Human", "Kenku", "Kobold", "Leonin",
|
| 108 |
"Lizardfolk", "Minotaur", "Orc", "Owlin", "Satyr", "Shadar-kai", "Shifter", "Tabaxi",
|
| 109 |
"Tiefling", "Tortle", "Triton", "Warforged", "Yuan-ti"
|
| 110 |
+
], multiselect=True, label="Character Race")
|
| 111 |
character_alignment = gr.Dropdown(["Lawful Good", "Neutral Good", "Chaotic Good", "Lawful Neutral", "True Neutral", "Chaotic Neutral", "Lawful Evil", "Neutral Evil", "Chaotic Evil"], label="Character Alignment", elem_classes="alignment_radio")
|
| 112 |
+
character_level=gr.Textbox(label = "Character Level")
|
| 113 |
|
| 114 |
|
| 115 |
with gr.Column(scale=2):
|