Spaces:
Runtime error
Runtime error
Create app1.py
Browse files
app1.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import InferenceClient
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
client = InferenceClient("""K00B404/BagOMistral_14X_Coders-ties-7B"""))
|
5 |
+
|
6 |
+
def format_prompt(message, history, model):
|
7 |
+
prompt = f"[INST] {message} [/INST]"
|
8 |
+
for user_prompt, bot_response in history:
|
9 |
+
prompt += f"[INST] {user_prompt} [/"
|
10 |
+
prompt += f" {bot_response} [/"
|
11 |
+
prompt = f"[MODEL] {model} [/" + prompt
|
12 |
+
return prompt
|
13 |
+
|
14 |
+
def generate(prompt, history, temperature=0.2, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0, model="BagOMistral_14X_Coders-ties-7B"):
|
15 |
+
temperature = float(temperature)
|
16 |
+
if temperature < 1e-2:
|
17 |
+
temperature = 1e-2
|
18 |
+
top_p = float(top_p)
|
19 |
+
|
20 |
+
generate_kwargs = dict(
|
21 |
+
temperature=temperature,
|
22 |
+
max_new_tokens=max_new_tokens,
|
23 |
+
top_p=top_p,
|
24 |
+
repetition_penalty=repetition_penalty,
|
25 |
+
do_sample=True,
|
26 |
+
seed=42,
|
27 |
+
)
|
28 |
+
|
29 |
+
formatted_prompt = format_prompt(prompt, history, model)
|
30 |
+
|
31 |
+
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
32 |
+
output = ""
|
33 |
+
|
34 |
+
for response in stream:
|
35 |
+
output += response.token.text
|
36 |
+
yield output
|
37 |
+
return output
|
38 |
+
|
39 |
+
mychatbot = gr.Chatbot(avatar_images=["./user.png", "./botm.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True)
|
40 |
+
|
41 |
+
model_options = ["BagOMistral_14X_Coders-ties-7B", "Model2", "Model3", "Model4", "Model5", "Model6", "Model7"]
|
42 |
+
|
43 |
+
demo = gr.ChatInterface(fn=generate,
|
44 |
+
chatbot=mychatbot,
|
45 |
+
title="K00B404's Merged Models Test Chat",
|
46 |
+
retry_btn=None,
|
47 |
+
undo_btn=None,
|
48 |
+
inputs=["text", "history", "temperature", "max_new_tokens", "top_p", "repetition_penalty", "model"],
|
49 |
+
inputs_types={"model": "dropdown", "text": "text", "history": "text", "temperature": "number", "max_new_tokens": "number", "top_p": "number", "repetition_penalty": "number"},
|
50 |
+
input_labels={"model": "Select Model", "text": "Enter Prompt", "history": "Chat History", "temperature": "Temperature", "max_new_tokens": "Max New Tokens", "top_p": "Top P", "repetition_penalty": "Repetition Penalty"},
|
51 |
+
input_options={"model": model_options})
|
52 |
+
|
53 |
+
demo.queue().launch(show_api=False)
|