tolulope commited on
Commit
4fa9a8c
·
verified ·
1 Parent(s): a606cad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -36
app.py CHANGED
@@ -1,44 +1,34 @@
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("JerniganLab/interviews-and-qa")
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:
21
- if val[0]:
22
- messages.append({"role": "user", "content": val[0]})
23
- if val[1]:
24
- messages.append({"role": "assistant", "content": val[1]})
25
 
26
- messages.append({"role": "user", "content": message})
27
-
28
- response = ""
 
 
 
29
 
30
- for message in client.chat_completion(
 
 
 
31
  messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
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
 
1
  import gradio as gr
2
+ import transformers
3
+ import torch
4
 
5
+ model_id = "JerniganLab/interviews-and-qa"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ pipeline = transformers.pipeline(
8
+ "text-generation",
9
+ model=model_id,
10
+ model_kwargs={"torch_dtype": torch.bfloat16},
11
+ device="cuda",
12
+ )
13
 
14
+ def chat_function(message, history, system_prompt, max_new_tokens, temperature):
15
+ messages = [{"role":"system","content":system_prompt},
16
+ {"role":"user", "content":message}]
17
+ prompt = pipeline.tokenizer.apply_chat_template(
18
  messages,
19
+ tokenize=False,
20
+ add_generation_prompt=True,)
21
+ terminators = [
22
+ pipeline.tokenizer.eos_token_id,
23
+ pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>")]
24
+ outputs = pipeline(
25
+ prompt,
26
+ max_new_tokens = max_new_tokens,
27
+ eos_token_id = terminators,
28
+ do_sample = True,
29
+ temperature = temperature + 0.1,
30
+ top_p = 0.9,)
31
+ return outputs[0]["generated_text"][len(prompt):]
32
 
33
  """
34
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface