Delete app.py
Browse files
app.py
DELETED
|
@@ -1,55 +0,0 @@
|
|
| 1 |
-
import kminterface
|
| 2 |
-
import requests
|
| 3 |
-
import json
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def tokenize(text):
|
| 7 |
-
return text
|
| 8 |
-
# return tok.encode(text, add_special_tokens=False)
|
| 9 |
-
|
| 10 |
-
def format_prompt(message, history):
|
| 11 |
-
prompt = ""
|
| 12 |
-
for user_prompt, bot_response in history:
|
| 13 |
-
prompt += "<s>" + tokenize("[INST]") + tokenize(user_prompt) + tokenize("[/INST]")
|
| 14 |
-
prompt += tokenize(bot_response) + "</s> "
|
| 15 |
-
prompt += tokenize("[INST]") + tokenize(message) + tokenize("[/INST]")
|
| 16 |
-
return prompt
|
| 17 |
-
|
| 18 |
-
def generate(prompt, history, system_prompt, temperature=0.2, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0):
|
| 19 |
-
print(type(history), history)
|
| 20 |
-
temperature = float(temperature)
|
| 21 |
-
if temperature < 1e-2:
|
| 22 |
-
temperature = 1e-2
|
| 23 |
-
top_p = float(top_p)
|
| 24 |
-
|
| 25 |
-
generate_kwargs = dict(
|
| 26 |
-
temperature=temperature,
|
| 27 |
-
max_new_tokens=max_new_tokens,
|
| 28 |
-
top_p=top_p,
|
| 29 |
-
repetition_penalty=repetition_penalty,
|
| 30 |
-
do_sample=True,
|
| 31 |
-
seed=42,
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
| 35 |
-
|
| 36 |
-
stream = kminterface.client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 37 |
-
output = ""
|
| 38 |
-
|
| 39 |
-
for response in stream:
|
| 40 |
-
print(response.token.text + "/n")
|
| 41 |
-
output += response.token.text
|
| 42 |
-
yield output
|
| 43 |
-
return output
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
demo = kminterface.gr.ChatInterface(fn=generate,
|
| 48 |
-
chatbot=kminterface.mychatbot,
|
| 49 |
-
additional_inputs=kminterface.additional_inputs,
|
| 50 |
-
title="Kamran's Mixtral 8x7b Chat",
|
| 51 |
-
retry_btn=None,
|
| 52 |
-
undo_btn=None
|
| 53 |
-
)
|
| 54 |
-
|
| 55 |
-
demo.queue().launch(show_api=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|