accesscreate012 commited on
Commit
162f57a
·
verified ·
1 Parent(s): 800c884

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -18
app.py CHANGED
@@ -1,12 +1,32 @@
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
6
- """
7
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
8
 
 
 
 
 
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  def respond(
11
  message,
12
  history: list[tuple[str, str]],
@@ -15,8 +35,8 @@ def respond(
15
  temperature,
16
  top_p,
17
  ):
 
18
  messages = [{"role": "system", "content": system_message}]
19
-
20
  for val in history:
21
  if val[0]:
22
  messages.append({"role": "user", "content": val[0]})
@@ -35,30 +55,20 @@ def respond(
35
  top_p=top_p,
36
  ):
37
  token = message.choices[0].delta.content
38
-
39
  response += token
40
  yield response
41
 
42
-
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
  demo = gr.ChatInterface(
47
  respond,
48
  additional_inputs=[
49
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
55
- value=0.95,
56
- step=0.05,
57
- label="Top-p (nucleus sampling)",
58
- ),
59
  ],
60
  )
61
 
62
-
63
  if __name__ == "__main__":
64
  demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ from datasets import load_dataset
4
+ import threading
5
+ import time
6
 
7
+ # Initialize the InferenceClient for Zephyr model
 
 
8
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
9
 
10
+ # Function to load the latest dataset from Hugging Face
11
+ def load_data():
12
+ dataset = load_dataset("accesscreate012/abhinav-academy-chatbot", split="train")
13
+ return {entry["question"]: entry["answer"] for entry in dataset}
14
 
15
+ # Global variable to store the dataset
16
+ data = load_data()
17
+
18
+ # Function to update dataset every 24 hours
19
+ def auto_update():
20
+ global data
21
+ while True:
22
+ time.sleep(86400) # Wait for 24 hours before refreshing dataset
23
+ data = load_data() # Reload the dataset
24
+ print("Dataset updated.")
25
+
26
+ # Start the auto-update thread (runs in the background)
27
+ threading.Thread(target=auto_update, daemon=True).start()
28
+
29
+ # Chatbot response function using the InferenceClient
30
  def respond(
31
  message,
32
  history: list[tuple[str, str]],
 
35
  temperature,
36
  top_p,
37
  ):
38
+ # Prepare the message history for the model
39
  messages = [{"role": "system", "content": system_message}]
 
40
  for val in history:
41
  if val[0]:
42
  messages.append({"role": "user", "content": val[0]})
 
55
  top_p=top_p,
56
  ):
57
  token = message.choices[0].delta.content
 
58
  response += token
59
  yield response
60
 
61
+ # Gradio interface
 
 
 
62
  demo = gr.ChatInterface(
63
  respond,
64
  additional_inputs=[
65
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
66
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max Tokens"),
67
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
68
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
 
 
 
 
 
 
69
  ],
70
  )
71
 
72
+ # Launch the interface
73
  if __name__ == "__main__":
74
  demo.launch()