upd app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ import faiss
|
|
4 |
import numpy as np
|
5 |
import os
|
6 |
import time
|
7 |
-
import json
|
8 |
import threading # β
Run embeddings in parallel
|
9 |
|
10 |
# β
Ensure FAISS is installed
|
@@ -13,35 +12,7 @@ os.system("pip install faiss-cpu")
|
|
13 |
def log(message):
|
14 |
print(f"β
{message}")
|
15 |
|
16 |
-
|
17 |
-
os.makedirs(DATA_DIR, exist_ok=True) # Ensure directory exists
|
18 |
-
|
19 |
-
# β
Step 1: Load Datasets from HF and Save Locally
|
20 |
-
datasets = {
|
21 |
-
"sales": "goendalf666/sales-conversations",
|
22 |
-
"blended": "blended_skill_talk",
|
23 |
-
"dialog": "daily_dialog",
|
24 |
-
"multiwoz": "multi_woz_v22",
|
25 |
-
}
|
26 |
-
|
27 |
-
for name, hf_name in datasets.items():
|
28 |
-
file_path = os.path.join(DATA_DIR, f"{name}.json")
|
29 |
-
|
30 |
-
if os.path.exists(file_path):
|
31 |
-
log(f"β
{name} dataset already stored at {file_path}")
|
32 |
-
continue # Skip if dataset exists
|
33 |
-
|
34 |
-
log(f"π₯ Downloading {name} dataset...")
|
35 |
-
dataset = load_dataset(hf_name)
|
36 |
-
train_data = dataset["train"]
|
37 |
-
data_list = [dict(row) for row in train_data]
|
38 |
-
|
39 |
-
with open(file_path, "w") as f:
|
40 |
-
json.dump(data_list, f, indent=2)
|
41 |
-
|
42 |
-
log(f"β
{name} dataset saved to {file_path}")
|
43 |
-
|
44 |
-
# β
Step 2: Run Embeddings in a Separate Thread
|
45 |
def run_embeddings():
|
46 |
log("π Running embeddings script in background...")
|
47 |
import embeddings # β
This will automatically run embeddings.py
|
@@ -50,7 +21,7 @@ def run_embeddings():
|
|
50 |
embedding_thread = threading.Thread(target=run_embeddings)
|
51 |
embedding_thread.start() # β
Start embedding in background
|
52 |
|
53 |
-
# β
Step
|
54 |
def check_faiss():
|
55 |
index_path = "my_embeddings.faiss" # Ensure file has .faiss extension
|
56 |
|
@@ -69,7 +40,7 @@ log("π Checking FAISS embeddings...")
|
|
69 |
faiss_status = check_faiss()
|
70 |
log(faiss_status)
|
71 |
|
72 |
-
# β
Step
|
73 |
client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
|
74 |
|
75 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
@@ -91,7 +62,7 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
91 |
response += token
|
92 |
yield response
|
93 |
|
94 |
-
# β
Step
|
95 |
demo = gr.ChatInterface(
|
96 |
respond,
|
97 |
additional_inputs=[
|
@@ -104,5 +75,4 @@ demo = gr.ChatInterface(
|
|
104 |
|
105 |
log("β
All systems go! Launching chatbot...")
|
106 |
if __name__ == "__main__":
|
107 |
-
demo.launch()
|
108 |
-
|
|
|
4 |
import numpy as np
|
5 |
import os
|
6 |
import time
|
|
|
7 |
import threading # β
Run embeddings in parallel
|
8 |
|
9 |
# β
Ensure FAISS is installed
|
|
|
12 |
def log(message):
|
13 |
print(f"β
{message}")
|
14 |
|
15 |
+
# β
Step 1: Run Embeddings in a Separate Thread
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
def run_embeddings():
|
17 |
log("π Running embeddings script in background...")
|
18 |
import embeddings # β
This will automatically run embeddings.py
|
|
|
21 |
embedding_thread = threading.Thread(target=run_embeddings)
|
22 |
embedding_thread.start() # β
Start embedding in background
|
23 |
|
24 |
+
# β
Step 2: Check FAISS index
|
25 |
def check_faiss():
|
26 |
index_path = "my_embeddings.faiss" # Ensure file has .faiss extension
|
27 |
|
|
|
40 |
faiss_status = check_faiss()
|
41 |
log(faiss_status)
|
42 |
|
43 |
+
# β
Step 3: Initialize Chatbot
|
44 |
client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.3")
|
45 |
|
46 |
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
|
62 |
response += token
|
63 |
yield response
|
64 |
|
65 |
+
# β
Step 4: Start Chatbot Interface
|
66 |
demo = gr.ChatInterface(
|
67 |
respond,
|
68 |
additional_inputs=[
|
|
|
75 |
|
76 |
log("β
All systems go! Launching chatbot...")
|
77 |
if __name__ == "__main__":
|
78 |
+
demo.launch()
|
|