khanhamzawiser commited on
Commit
7382b20
·
verified ·
1 Parent(s): 5b97a1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -41
app.py CHANGED
@@ -1,24 +1,13 @@
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
- demo = gr.ChatInterface(..., title="Wiser AI Assistant")
10
-
11
-
12
- def respond(
13
- message,
14
- history: list[tuple[str, str]],
15
- system_message,
16
- max_tokens,
17
- temperature,
18
- top_p,
19
- ):
20
  messages = [{"role": "system", "content": system_message}]
21
-
22
  for val in history:
23
  if val[0]:
24
  messages.append({"role": "user", "content": val[0]})
@@ -26,7 +15,6 @@ def respond(
26
  messages.append({"role": "assistant", "content": val[1]})
27
 
28
  messages.append({"role": "user", "content": message})
29
-
30
  response = ""
31
 
32
  for message in client.chat_completion(
@@ -37,36 +25,40 @@ def respond(
37
  top_p=top_p,
38
  ):
39
  token = message.choices[0].delta.content
40
-
41
  response += token
42
  yield response
43
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
- """
46
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
47
- """
48
- demo = gr.ChatInterface(
49
- respond,
50
- title="🤖 Wiser AI Assistant",
51
- description="Your smart manufacturing assistant powered by Wiser Machines. Ask me anything about automation, productivity, factory operations, or how Wiser can help!",
52
- additional_inputs=[
53
- gr.Textbox(value="You are Wiser, an AI assistant specializing in smart manufacturing and factory automation. Respond clearly, concisely, and use real-world manufacturing examples when needed.", label="System message"),
54
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
55
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
56
- gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
57
- ],
58
- )
59
-
60
-
61
- demo = gr.ChatInterface(..., title="Wiser AI Assistant")
62
-
63
- if __name__ == "__main__":
64
- with gr.Blocks() as demo:
65
- gr.Markdown("## Welcome to Wiser AI Assistant")
66
- gr.Markdown("Ask questions about factory automation, productivity, or how Wiser Machines can help streamline your operations.")
67
- chat = gr.ChatInterface(
68
  respond,
69
- additional_inputs=[...], # your sliders and system message
 
 
 
 
 
 
 
 
70
  )
71
 
 
 
72
  demo.launch()
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ # Load the Zephyr model from Hugging Face
 
 
5
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
 
7
+ # Define how the chatbot responds
8
+ def respond(message, history: list[tuple[str, str]], system_message, max_tokens, temperature, top_p):
 
 
 
 
 
 
 
 
 
9
  messages = [{"role": "system", "content": system_message}]
10
+
11
  for val in history:
12
  if val[0]:
13
  messages.append({"role": "user", "content": val[0]})
 
15
  messages.append({"role": "assistant", "content": val[1]})
16
 
17
  messages.append({"role": "user", "content": message})
 
18
  response = ""
19
 
20
  for message in client.chat_completion(
 
25
  top_p=top_p,
26
  ):
27
  token = message.choices[0].delta.content
 
28
  response += token
29
  yield response
30
 
31
+ # Build the UI using Gradio Blocks
32
+ with gr.Blocks() as demo:
33
+ gr.Image("logo.png", height=80, show_label=False, show_download_button=False)
34
+ gr.Markdown("## 🤖 Wiser AI Assistant")
35
+ gr.Markdown(
36
+ """
37
+ Welcome to **Wiser's AI Assistant**, your smart companion for all things manufacturing.
38
+ Ask questions about:
39
+ - Smart factory operations 🏭
40
+ - Workflow automation ⚙️
41
+ - Efficiency tips 📈
42
+ - Wiser’s AI-powered solutions 🧠
43
 
44
+ Learn how Wiser Machines can help transform your production floor!
45
+ """
46
+ )
47
+
48
+ gr.ChatInterface(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  respond,
50
+ additional_inputs=[
51
+ gr.Textbox(
52
+ value="You are Wiser, an expert AI assistant in smart manufacturing. Help users improve factory productivity and explain Wiser’s solutions with confidence.",
53
+ label="System message"
54
+ ),
55
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
56
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
57
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
58
+ ],
59
  )
60
 
61
+ # Run the app
62
+ if __name__ == "__main__":
63
  demo.launch()
64
+