drewvid commited on
Commit
9f927e0
·
verified ·
1 Parent(s): 333a6bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -5
app.py CHANGED
@@ -4,17 +4,39 @@ from huggingface_hub import InferenceClient
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]],
13
- system_message,
14
  max_tokens,
15
  temperature,
16
  top_p,
17
  ):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  messages = [{"role": "system", "content": system_message}]
19
 
20
  for val in history:
@@ -36,8 +58,9 @@ def respond(
36
  ):
37
  token = message.choices[0].delta.content
38
 
39
- response += token
40
- yield response
 
41
 
42
  """
43
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
@@ -45,7 +68,6 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
45
  demo = gr.ChatInterface(
46
  respond,
47
  additional_inputs=[
48
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
49
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
50
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
51
  gr.Slider(
 
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
+ client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
9
 
10
 
11
  def respond(
12
  message,
13
  history: list[tuple[str, str]],
 
14
  max_tokens,
15
  temperature,
16
  top_p,
17
  ):
18
+
19
+ name = "Ernest"
20
+
21
+ system_message = f"""You are a supportive and knowledgeable mentor in the English language called {name}. You are also an expert in:
22
+
23
+ 1) Minsky's Frame System Theory;
24
+ 2) Role Theory;
25
+ 3) Haliday's Functional Grammar;
26
+ 4) Speech Acts.
27
+
28
+ Provide detailed, patient explanations and guidance on language usage, grammar, vocabulary, and communication skills within the context of the above theories. Tailor your responses to the learner’s level, whether they are a beginner, intermediate, or advanced English speaker. Offer encouragement and constructive feedback to help build confidence and improve proficiency. Where appropriate, include examples and analogies to clarify points, and suggest exercises or activities to reinforce learning. Be attentive to the user’s questions and responsive in a manner that promotes a positive and engaging learning experience.
29
+
30
+ Example user prompts are:
31
+
32
+ 1) "Please create a Language Frame for a visit to the dentist with useful phrases and vocabulary grouped according to roles, speech acts, and functional grammar.";
33
+ 2) "Please create a Language Frame for going skiing with useful phrases and vocabulary grouped according to speech acts and roles.";
34
+ 3) "I am planning a trip to a foreign country. Please create a Language Frame to help me at the travel agents, with vocabulary and phrases grouped according to roles and speech acts.";
35
+ 4) "How can you help me?";
36
+ 5) "Who are you?".
37
+
38
+ """
39
+
40
  messages = [{"role": "system", "content": system_message}]
41
 
42
  for val in history:
 
58
  ):
59
  token = message.choices[0].delta.content
60
 
61
+ if token:
62
+ response += token
63
+ yield response
64
 
65
  """
66
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
 
68
  demo = gr.ChatInterface(
69
  respond,
70
  additional_inputs=[
 
71
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
72
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
73
  gr.Slider(