Philippe Kaplan commited on
Commit
26dc6e6
·
1 Parent(s): 5b9bb60
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -2,18 +2,17 @@ from huggingface_hub import InferenceClient
2
 
3
  import gradio as gr
4
 
5
- client = InferenceClient(
6
- "mistralai/Mistral-7B-Instruct-v0.3"
7
- )
8
 
9
- def format_prompt(message, history, system_message=None):
10
- prompt = "<s>"
 
11
  for user_prompt, bot_response in history:
12
- prompt += f"[INST] {user_prompt} [/INST]"
13
- prompt += f" {bot_response}</s> "
14
- if system_message:
15
- prompt += f"[SYS] {system_message} [/SYS]"
16
- prompt += f"[INST] {message} [/INST]"
17
  return prompt
18
 
19
  def generate(
@@ -32,7 +31,7 @@ def generate(
32
  seed=42,
33
  )
34
 
35
- formatted_prompt = format_prompt(prompt, history, system_message)
36
 
37
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
38
  output = ""
@@ -94,5 +93,5 @@ gr.ChatInterface(
94
  fn=generate,
95
  chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
96
  additional_inputs=additional_inputs,
97
- title="""mistralai/Mistral-7B-Instruct-v0.3"""
98
  ).launch(show_api=True)
 
2
 
3
  import gradio as gr
4
 
5
+ model_path = "ibm-granite/granite-34b-code-instruct-8k"
6
+ model_path="ibm-granite/granite-3b-code-instruct-2k"
7
+ client = InferenceClient(model_path)
8
 
9
+
10
+ def format_prompt(system, message, history):
11
+ prompt = [{"role": "system", "content": system}]
12
  for user_prompt, bot_response in history:
13
+ prompt += {"role": "user", "content": user_prompt}
14
+ prompt += {"role": "assistant", "content": bot_response}
15
+ prompt += {"role": "user", "content": message}
 
 
16
  return prompt
17
 
18
  def generate(
 
31
  seed=42,
32
  )
33
 
34
+ formatted_prompt = format_prompt(system_message, prompt, history)
35
 
36
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
37
  output = ""
 
93
  fn=generate,
94
  chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
95
  additional_inputs=additional_inputs,
96
+ title=model_path
97
  ).launch(show_api=True)