Spaces:
Build error
Build error
auth
Browse files
app.py
CHANGED
|
@@ -1,13 +1,18 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from tools import create_agent
|
| 4 |
from langchain_core.messages import RemoveMessage
|
| 5 |
from langchain_core.messages import trim_messages
|
| 6 |
-
|
| 7 |
-
# from langchain.schema import AIMessage, HumanMessage, SystemMessage
|
| 8 |
|
|
|
|
|
|
|
|
|
|
| 9 |
AGENT = create_agent()
|
| 10 |
theme = gr.themes.Default(primary_hue="red", secondary_hue="red")
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def filter_msg(msg_list:list, keep_n:int) -> list:
|
| 13 |
"""Keep only last keep_n messages from chat history. Preserves structure user msg -> tool msg -> ai msg"""
|
|
@@ -55,7 +60,7 @@ def delete_agent():
|
|
| 55 |
|
| 56 |
with gr.Blocks(theme=theme, js=js_func, title="Dataltist", fill_height=True) as iface:
|
| 57 |
gr.Markdown("# Dataltist Chatbot 🚀")
|
| 58 |
-
chatbot = gr.Chatbot(show_copy_button=True, show_share_button=False, type="messages", scale=1)
|
| 59 |
msg = gr.Textbox(lines=1, show_label=False, placeholder="Posez vos questions sur l'assurance") # submit_btn=True
|
| 60 |
# clear = gr.ClearButton([msg, chatbot], value="Effacer 🗑")
|
| 61 |
config = {"configurable": {"thread_id": "1"}}
|
|
@@ -78,4 +83,4 @@ with gr.Blocks(theme=theme, js=js_func, title="Dataltist", fill_height=True) as
|
|
| 78 |
iface.unload(delete_agent)
|
| 79 |
|
| 80 |
if __name__ == "__main__":
|
| 81 |
-
iface.launch(
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
import gradio as gr
|
| 4 |
from tools import create_agent
|
| 5 |
from langchain_core.messages import RemoveMessage
|
| 6 |
from langchain_core.messages import trim_messages
|
| 7 |
+
load_dotenv()
|
|
|
|
| 8 |
|
| 9 |
+
# Global params
|
| 10 |
+
AUTH_ID = os.environ.get("AUTH_ID")
|
| 11 |
+
AUTH_PASS = os.environ.get("AUTH_PASS")
|
| 12 |
AGENT = create_agent()
|
| 13 |
theme = gr.themes.Default(primary_hue="red", secondary_hue="red")
|
| 14 |
+
default_msg = "Bonjour ! Je suis là pour répondre à vos questions sur l'actuariat. Comment puis-je vous aider aujourd'hui ?"
|
| 15 |
+
|
| 16 |
|
| 17 |
def filter_msg(msg_list:list, keep_n:int) -> list:
|
| 18 |
"""Keep only last keep_n messages from chat history. Preserves structure user msg -> tool msg -> ai msg"""
|
|
|
|
| 60 |
|
| 61 |
with gr.Blocks(theme=theme, js=js_func, title="Dataltist", fill_height=True) as iface:
|
| 62 |
gr.Markdown("# Dataltist Chatbot 🚀")
|
| 63 |
+
chatbot = gr.Chatbot(show_copy_button=True, show_share_button=False, value=[{"role":"assistant", "content":default_msg}], type="messages", scale=1)
|
| 64 |
msg = gr.Textbox(lines=1, show_label=False, placeholder="Posez vos questions sur l'assurance") # submit_btn=True
|
| 65 |
# clear = gr.ClearButton([msg, chatbot], value="Effacer 🗑")
|
| 66 |
config = {"configurable": {"thread_id": "1"}}
|
|
|
|
| 83 |
iface.unload(delete_agent)
|
| 84 |
|
| 85 |
if __name__ == "__main__":
|
| 86 |
+
iface.launch(auth=(AUTH_ID, AUTH_PASS))
|
tools.py
CHANGED
|
@@ -41,13 +41,13 @@ memoires_ds = load_dataset("eliot-hub/memoires_vec_800", split="data", token=HF_
|
|
| 41 |
batched_ds = memoires_ds.batch(batch_size=41000)
|
| 42 |
client = chromadb.Client()
|
| 43 |
collection = client.get_or_create_collection(name="embeddings_mxbai")
|
| 44 |
-
for batch in tqdm(batched_ds, desc="Processing dataset batches"):
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
print(f"Collection complete: {collection.count()}")
|
| 52 |
del memoires_ds, batched_ds
|
| 53 |
|
|
|
|
| 41 |
batched_ds = memoires_ds.batch(batch_size=41000)
|
| 42 |
client = chromadb.Client()
|
| 43 |
collection = client.get_or_create_collection(name="embeddings_mxbai")
|
| 44 |
+
# for batch in tqdm(batched_ds, desc="Processing dataset batches"):
|
| 45 |
+
# collection.add(
|
| 46 |
+
# ids=batch["id"],
|
| 47 |
+
# metadatas=batch["metadata"],
|
| 48 |
+
# documents=batch["document"],
|
| 49 |
+
# embeddings=batch["embedding"],
|
| 50 |
+
# )
|
| 51 |
print(f"Collection complete: {collection.count()}")
|
| 52 |
del memoires_ds, batched_ds
|
| 53 |
|