johann22 commited on
Commit
8055050
1 Parent(s): 808da46

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +113 -1
app.py CHANGED
@@ -7,6 +7,116 @@ client = InferenceClient(
7
 
8
 
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  def format_prompt(message, history):
11
  prompt = "<s>"
12
  for user_prompt, bot_response in history:
@@ -103,4 +213,6 @@ gr.ChatInterface(
103
  title="Mixtral 46.7B",
104
  examples=examples,
105
  concurrency_limit=20,
106
- ).launch(show_api=False)
 
 
 
7
 
8
 
9
 
10
+ def format_prompt(message, history):
11
+ prompt = "<s>"
12
+ for user_prompt, bot_response in history:
13
+ prompt += f"[INST] {user_prompt} [/INST]"
14
+ prompt += f" {bot_response}</s> "
15
+ prompt += f"[INST] {message} [/INST]"
16
+ return prompt
17
+
18
+ def generate(
19
+ prompt, system_prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0, history,
20
+ ):
21
+ system_prompt=prompts.WEB_DEV
22
+ temperature = float(temperature)
23
+ if temperature < 1e-2:
24
+ temperature = 1e-2
25
+ top_p = float(top_p)
26
+
27
+ generate_kwargs = dict(
28
+ temperature=temperature,
29
+ max_new_tokens=max_new_tokens,
30
+ top_p=top_p,
31
+ repetition_penalty=repetition_penalty,
32
+ do_sample=True,
33
+ seed=42,
34
+ )
35
+
36
+ formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
37
+ stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
38
+ output = ""
39
+
40
+ for response in stream:
41
+ output += response.token.text
42
+ yield output
43
+ return output
44
+
45
+
46
+ additional_inputs=[
47
+ gr.Textbox(
48
+ label="Prompt",
49
+ max_lines=1,
50
+ interactive=True,
51
+ ),
52
+ gr.Slider(
53
+ label="Temperature",
54
+ value=0.9,
55
+ minimum=0.0,
56
+ maximum=1.0,
57
+ step=0.05,
58
+ interactive=True,
59
+ info="Higher values produce more diverse outputs",
60
+ ),
61
+
62
+ gr.Slider(
63
+ label="Max new tokens",
64
+ value=1048*10,
65
+ minimum=0,
66
+ maximum=1048*10,
67
+ step=64,
68
+ interactive=True,
69
+ info="The maximum numbers of new tokens",
70
+ ),
71
+ gr.Slider(
72
+ label="Top-p (nucleus sampling)",
73
+ value=0.90,
74
+ minimum=0.0,
75
+ maximum=1,
76
+ step=0.05,
77
+ interactive=True,
78
+ info="Higher values sample more low-probability tokens",
79
+ ),
80
+ gr.Slider(
81
+ label="Repetition penalty",
82
+ value=1.2,
83
+ minimum=1.0,
84
+ maximum=2.0,
85
+ step=0.05,
86
+ interactive=True,
87
+ info="Penalize repeated tokens",
88
+ )
89
+ ]
90
+
91
+ examples=[["I'm planning a vacation to Japan. Can you suggest a one-week itinerary including must-visit places and local cuisines to try?", None, None, None, None, None, ],
92
+ ["Can you write a short story about a time-traveling detective who solves historical mysteries?", None, None, None, None, None,],
93
+ ["I'm trying to learn French. Can you provide some common phrases that would be useful for a beginner, along with their pronunciations?", None, None, None, None, None,],
94
+ ["I have chicken, rice, and bell peppers in my kitchen. Can you suggest an easy recipe I can make with these ingredients?", None, None, None, None, None,],
95
+ ["Can you explain how the QuickSort algorithm works and provide a Python implementation?", None, None, None, None, None,],
96
+ ["What are some unique features of Rust that make it stand out compared to other systems programming languages like C++?", None, None, None, None, None,],
97
+ ]
98
+
99
+ gr.Interface(
100
+ fn=generate,
101
+ outputs=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
102
+ inputs=[additional_inputs,outputs],
103
+ title="Mixtral 46.7B",
104
+ examples=examples,
105
+ concurrency_limit=20,
106
+ ).launch(show_api=False)
107
+
108
+
109
+
110
+ """
111
+ from huggingface_hub import InferenceClient
112
+ import gradio as gr
113
+ import prompts
114
+ client = InferenceClient(
115
+ "mistralai/Mixtral-8x7B-Instruct-v0.1"
116
+ )
117
+
118
+
119
+
120
  def format_prompt(message, history):
121
  prompt = "<s>"
122
  for user_prompt, bot_response in history:
 
213
  title="Mixtral 46.7B",
214
  examples=examples,
215
  concurrency_limit=20,
216
+ ).launch(show_api=False)
217
+
218
+ """