Spaces:
Running
Running
"""Answer questions about my resume.""" | |
# %% IMPORTS | |
import logging | |
import gradio as gr | |
import tiktoken | |
import lib | |
# %% LOGGING | |
logging.basicConfig( | |
level=logging.INFO, | |
format="[%(asctime)s][%(levelname)s] %(message)s", | |
) | |
# %% CONFIGS | |
THEME = "glass" | |
TITLE = "Fmind Chatbot" | |
CLIENT = lib.get_database_client(path=lib.DATABASE_PATH) | |
ENCODING = tiktoken.get_encoding(encoding_name=lib.EMBEDDING_TOKENIZER) | |
FUNCTION = lib.get_embedding_function() | |
COLLECTION = CLIENT.get_collection( | |
name=lib.DATABASE_COLLECTION, | |
embedding_function=FUNCTION, | |
) | |
EXAMPLES = [ | |
"Who is Médéric Hurier (Fmind)?", | |
"Is Fmind open to new opportunities?", | |
"What is Médéric's most recent degree?", | |
"What is Médéric's latest work experience?", | |
"Is Médéric proficient in Python programming?", | |
] | |
# %% FUNCTIONS | |
def answer(message: str, history: list[str]) -> str: | |
"""Answer questions about my resume.""" | |
tokens = ENCODING.encode(message) | |
print("History:", len(history)) | |
print("Tokens:", len(tokens)) | |
return message | |
# %% INTERFACES | |
interface = gr.ChatInterface( | |
fn=answer, | |
theme=THEME, | |
title=TITLE, | |
examples=EXAMPLES, | |
clear_btn=None, | |
retry_btn=None, | |
undo_btn=None, | |
) | |
# %% ENTRYPOINTS | |
if __name__ == "__main__": | |
interface.launch() | |