johann22 commited on
Commit
93a07fc
1 Parent(s): 9dc0c3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -112
app.py CHANGED
@@ -4,117 +4,6 @@ import prompts
4
  client = InferenceClient(
5
  "mistralai/Mixtral-8x7B-Instruct-v0.1"
6
  )
7
- chat_state=gr.JSON()
8
-
9
-
10
-
11
- def format_prompt(message, history):
12
- prompt = "<s>"
13
- for user_prompt, bot_response in history:
14
- prompt += f"[INST] {user_prompt} [/INST]"
15
- prompt += f" {bot_response}</s> "
16
- prompt += f"[INST] {message} [/INST]"
17
- return prompt
18
-
19
- def generate(
20
- prompt, system_prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0, history=chat_state,
21
- ):
22
- system_prompt=prompts.WEB_DEV
23
- temperature = float(temperature)
24
- if temperature < 1e-2:
25
- temperature = 1e-2
26
- top_p = float(top_p)
27
-
28
- generate_kwargs = dict(
29
- temperature=temperature,
30
- max_new_tokens=max_new_tokens,
31
- top_p=top_p,
32
- repetition_penalty=repetition_penalty,
33
- do_sample=True,
34
- seed=42,
35
- )
36
-
37
- formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
38
- stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
39
- output = ""
40
-
41
- for response in stream:
42
- output += response.token.text
43
- yield output
44
- return output,output
45
-
46
- output = [gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),chat_state]
47
- additional_inputs=[
48
- gr.Textbox(
49
- label="Prompt",
50
- max_lines=1,
51
- interactive=True,
52
- ),
53
- gr.Slider(
54
- label="Temperature",
55
- value=0.9,
56
- minimum=0.0,
57
- maximum=1.0,
58
- step=0.05,
59
- interactive=True,
60
- info="Higher values produce more diverse outputs",
61
- ),
62
-
63
- gr.Slider(
64
- label="Max new tokens",
65
- value=1048*10,
66
- minimum=0,
67
- maximum=1048*10,
68
- step=64,
69
- interactive=True,
70
- info="The maximum numbers of new tokens",
71
- ),
72
- gr.Slider(
73
- label="Top-p (nucleus sampling)",
74
- value=0.90,
75
- minimum=0.0,
76
- maximum=1,
77
- step=0.05,
78
- interactive=True,
79
- info="Higher values sample more low-probability tokens",
80
- ),
81
- gr.Slider(
82
- label="Repetition penalty",
83
- value=1.2,
84
- minimum=1.0,
85
- maximum=2.0,
86
- step=0.05,
87
- interactive=True,
88
- info="Penalize repeated tokens",
89
- ), chat_state
90
-
91
- ]
92
-
93
- 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, ],
94
- ["Can you write a short story about a time-traveling detective who solves historical mysteries?", None, None, None, None, None,],
95
- ["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,],
96
- ["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,],
97
- ["Can you explain how the QuickSort algorithm works and provide a Python implementation?", None, None, None, None, None,],
98
- ["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,],
99
- ]
100
- gr.Interface(
101
- fn=generate,
102
- outputs=output,
103
- inputs=additional_inputs,
104
- title="Mixtral 46.7B",
105
- examples=examples,
106
- concurrency_limit=20,
107
- ).launch(show_api=False)
108
-
109
-
110
-
111
- """
112
- from huggingface_hub import InferenceClient
113
- import gradio as gr
114
- import prompts
115
- client = InferenceClient(
116
- "mistralai/Mixtral-8x7B-Instruct-v0.1"
117
- )
118
 
119
 
120
 
@@ -216,4 +105,3 @@ gr.ChatInterface(
216
  concurrency_limit=20,
217
  ).launch(show_api=False)
218
 
219
- """
 
4
  client = InferenceClient(
5
  "mistralai/Mixtral-8x7B-Instruct-v0.1"
6
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
 
9
 
 
105
  concurrency_limit=20,
106
  ).launch(show_api=False)
107