Denyol commited on
Commit
b32b8c0
·
verified ·
1 Parent(s): f49ac5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -26
app.py CHANGED
@@ -1,14 +1,11 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
  import os
4
  import cohere
5
 
6
- """
7
- 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
- """
9
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
10
  COHERE_API_KEY = os.getenv("COHERE_API_KEY")
11
- client_cohere = cohere.Client(COHERE_API_KEY)
 
12
  COHERE_MODEL = "command-r-plus"
13
 
14
 
@@ -20,7 +17,7 @@ def respond(
20
  top_p,
21
  ):
22
 
23
- system_message = ('''
24
  You are a friendly chatbot who is also a video game recommendation expert.
25
  Your task is to help parents and guardians to find appropriate video games for their children.
26
  Extract the child's age, preferred genre and multiplayer preference.
@@ -48,7 +45,7 @@ def respond(
48
  If the requested genre is rare, explain why certain alternatives may be more suitable for the child's age.
49
 
50
  Only suggest video games that exist and are well-known. Do NOT make up game titles.
51
- ''')
52
 
53
  messages = [{"role": "system", "content": system_message}]
54
 
@@ -60,37 +57,21 @@ def respond(
60
 
61
  messages.append({"role": "user", "content": message})
62
 
63
- response = ""
64
-
65
- cohere_response = client_cohere.chat(
66
  messages=messages,
67
  model=COHERE_MODEL,
68
  temperature=temperature,
69
  max_tokens=max_tokens
70
  )
71
- response = cohere_response.text
72
  yield response
73
 
74
- '''
75
- for message in client.chat_completion(
76
- messages,
77
- max_tokens=max_tokens,
78
- stream=True,
79
- temperature=temperature,
80
- top_p=top_p,
81
- ):
82
- token = message.choices[0].delta.content
83
-
84
- response += token
85
- yield response
86
- '''
87
-
88
 
89
  """
90
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
91
  """
92
  demo = gr.ChatInterface(
93
  respond,
 
94
  additional_inputs=[
95
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
96
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
@@ -102,6 +83,7 @@ demo = gr.ChatInterface(
102
  label="Top-p (nucleus sampling)",
103
  ),
104
  ],
 
105
  )
106
 
107
 
 
1
  import gradio as gr
 
2
  import os
3
  import cohere
4
 
5
+
 
 
 
6
  COHERE_API_KEY = os.getenv("COHERE_API_KEY")
7
+ client = cohere.ClientV2(COHERE_API_KEY)
8
+
9
  COHERE_MODEL = "command-r-plus"
10
 
11
 
 
17
  top_p,
18
  ):
19
 
20
+ system_message = '''
21
  You are a friendly chatbot who is also a video game recommendation expert.
22
  Your task is to help parents and guardians to find appropriate video games for their children.
23
  Extract the child's age, preferred genre and multiplayer preference.
 
45
  If the requested genre is rare, explain why certain alternatives may be more suitable for the child's age.
46
 
47
  Only suggest video games that exist and are well-known. Do NOT make up game titles.
48
+ '''
49
 
50
  messages = [{"role": "system", "content": system_message}]
51
 
 
57
 
58
  messages.append({"role": "user", "content": message})
59
 
60
+ response = client.chat(
 
 
61
  messages=messages,
62
  model=COHERE_MODEL,
63
  temperature=temperature,
64
  max_tokens=max_tokens
65
  )
 
66
  yield response
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
  """
70
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
71
  """
72
  demo = gr.ChatInterface(
73
  respond,
74
+ '''
75
  additional_inputs=[
76
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
77
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
 
83
  label="Top-p (nucleus sampling)",
84
  ),
85
  ],
86
+ '''
87
  )
88
 
89