merethom commited on
Commit
8d32f69
·
verified ·
1 Parent(s): db6d982

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
 
3
 
4
  """
5
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
@@ -7,6 +8,11 @@ For more information on `huggingface_hub` Inference API support, please check th
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
9
 
 
 
 
 
 
10
  def respond(
11
  message,
12
  history: list[tuple[str, str]],
@@ -15,6 +21,18 @@ def respond(
15
  temperature,
16
  top_p,
17
  ):
 
 
 
 
 
 
 
 
 
 
 
 
18
  messages = [{"role": "system", "content": system_message}]
19
 
20
  for val in history:
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ from datasets import load_dataset # Import the datasets library
4
 
5
  """
6
  For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
 
8
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
9
 
10
 
11
+ # Load the dataset from Hugging Face
12
+ dataset = load_dataset("samhog/psychology-10k", split="train") # Load the training split
13
+
14
+
15
+
16
  def respond(
17
  message,
18
  history: list[tuple[str, str]],
 
21
  temperature,
22
  top_p,
23
  ):
24
+ # First, attempt to find a response in the dataset
25
+ closest_match = None
26
+ for entry in dataset:
27
+ if message.lower() in entry["question"].lower(): # Adjust "question" to the actual column name
28
+ closest_match = entry["answer"] # Adjust "answer" to the actual column name
29
+ break
30
+
31
+ # If a match is found, return the dataset answer
32
+ if closest_match:
33
+ return closest_match
34
+
35
+ # If no match is found, use the chatbot model
36
  messages = [{"role": "system", "content": system_message}]
37
 
38
  for val in history: