Nihal Nayak commited on
Commit
aecc737
1 Parent(s): e1ae004

reverting to init template

Browse files
Files changed (1) hide show
  1. app.py +37 -82
app.py CHANGED
@@ -1,108 +1,63 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
- # from transformers import AutoModelForCausalLM, AutoTokenizer
4
- # import spaces
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("BatsResearch/bonito-v1")
10
- # model = AutoModelForCausalLM.from_pretrained("BatsResearch/bonito-v1")
11
- # tokenizer = AutoTokenizer.from_pretrained("BatsResearch/bonito-v1")
12
 
13
- # move to cuda
14
- # model.to("cuda")
15
 
16
  def respond(
17
- context: str,
 
 
 
 
 
18
  ):
 
19
 
 
 
 
 
 
20
 
21
- # task_type = "extractive question answering"
22
- # input_text = "<|tasktype|>\n" + task_type.strip()
23
- # input_text += (
24
- # "\n<|context|>\n" + context.strip() + "\n<|task|>\n"
25
- # )
26
 
27
- # input_ids = tokenizer.encode(input_text, return_tensors="pt").to("cuda")
28
- # outputs = model.generate(
29
- # input_ids,
30
- # max_new_tokens=max_tokens,
31
- # temperature=temperature,
32
- # do_sample=True,
33
- # top_p=top_p,
34
- # )
35
- # pred_start = int(input_ids.shape[-1])
36
- # pred = tokenizer.decode(outputs[pred_start:], skip_special_tokens=True)
37
 
38
- # replace the context
39
- pred = ""
40
- return pred
41
-
42
-
43
- # for token in client.text_generation(input_text, max_tokens=max_tokens, temperature=temperature, top_p=top_p, stream=True):
44
- # yield token
45
-
46
- # messages = [{"role": "system", "content": system_message}]
47
-
48
- # for val in history:
49
- # if val[0]:
50
- # messages.append({"role": "user", "content": val[0]})
51
- # if val[1]:
52
- # messages.append({"role": "assistant", "content": val[1]})
53
-
54
- # messages.append({"role": "user", "content": message})
55
-
56
- # response = ""
57
-
58
- # for message in client.chat_completion(
59
- # messages,
60
- # max_tokens=max_tokens,
61
- # stream=True,
62
- # temperature=temperature,
63
- # top_p=top_p,
64
- # ):
65
- # token = message.choices[0].delta.content
66
-
67
- # response += token
68
- # yield response
69
 
 
 
70
 
71
  """
72
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
73
  """
74
-
75
- description = """
76
- This is Bonito.
77
- """
78
-
79
-
80
- examples = [
81
- "Hugging Face, Inc. is a French-American company incorporated under the Delaware General Corporation Law[1] and based in New York City that develops computation tools for building applications using machine learning. It is most notable for its transformers library built for natural language processing applications and its platform that allows users to share machine learning models and datasets and showcase their work.",
82
- "In order to make your Space work with ZeroGPU you need to decorate the Python functions that actually require a GPU with @spaces.GPU \n During the time when a decorated function is invoked, the Space will be attributed a GPU, and it will release it upon completion of the function.",
83
- "A spectre is haunting Europe – the spectre of communism. All the powers of old Europe have entered into a holy alliance to exorcise this spectre: Pope and Tsar, Metternich and Guizot, French Radicals and German police-spies"
84
- ]
85
-
86
- demo = gr.Interface(
87
  respond,
88
- # inputs=[gr.Textbox(lines=5, label="Enter context here"), gr.Dropdown(["extractive question answering"], label="Task Type")],
89
- inputs=gr.Textbox(lines=5, label="Enter context here"),
90
- outputs=gr.Textbox(lines=20, label="Generated Instruction-Response Pairs"),
91
  additional_inputs=[
92
- # gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
93
- # gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
94
- # gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
95
- # gr.Slider(
96
- # minimum=0.1,
97
- # maximum=1.0,
98
- # value=0.95,
99
- # step=0.05,
100
- # label="Top-p (nucleus sampling)",
101
- # ),
102
  ],
103
- description=description,
104
  )
105
 
106
 
107
  if __name__ == "__main__":
108
- demo.launch()
 
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
 
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
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
44
  """
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(
52
+ minimum=0.1,
53
+ maximum=1.0,
54
+ value=0.95,
55
+ step=0.05,
56
+ label="Top-p (nucleus sampling)",
57
+ ),
58
  ],
 
59
  )
60
 
61
 
62
  if __name__ == "__main__":
63
+ demo.launch()