abrah926 commited on
Commit
2ab9d34
Β·
verified Β·
1 Parent(s): 690b43c

upd app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -35
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
- DATA_DIR = "data"
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 3: Check FAISS index
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 4: Initialize Chatbot
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 5: Start Chatbot Interface
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() # βœ… FIXED typo
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()