Martin Vlach
commited on
Commit
β’
6d05e55
1
Parent(s):
6286da0
add app from https://github.com/ise-uiuc/magicoder/blob/main/demo
Browse files
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import argparse
|
3 |
+
import os
|
4 |
+
import json
|
5 |
+
from vllm import LLM, SamplingParams
|
6 |
+
|
7 |
+
|
8 |
+
def parse_args():
|
9 |
+
parser = argparse.ArgumentParser()
|
10 |
+
parser.add_argument("--base_model", type=str) # model path
|
11 |
+
parser.add_argument("--n_gpus", type=int, default=1) # n_gpu
|
12 |
+
return parser.parse_args()
|
13 |
+
|
14 |
+
def predict(message, history, system_prompt, temperature, max_tokens):
|
15 |
+
instruction = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. "
|
16 |
+
for human, assistant in history:
|
17 |
+
instruction += 'USER: '+ human + ' ASSISTANT: '+ assistant + '</s>'
|
18 |
+
instruction += 'USER: '+ message + ' ASSISTANT:'
|
19 |
+
problem = [instruction]
|
20 |
+
stop_tokens = ["USER:", "USER", "ASSISTANT:", "ASSISTANT"]
|
21 |
+
sampling_params = SamplingParams(temperature=temperature, top_p=1, max_tokens=max_tokens, stop=stop_tokens)
|
22 |
+
completions = llm.generate(problem, sampling_params)
|
23 |
+
for output in completions:
|
24 |
+
prompt = output.prompt
|
25 |
+
print('==========================question=============================')
|
26 |
+
print(prompt)
|
27 |
+
generated_text = output.outputs[0].text
|
28 |
+
print('===========================answer=============================')
|
29 |
+
print(generated_text)
|
30 |
+
for idx in range(len(generated_text)):
|
31 |
+
yield generated_text[:idx+1]
|
32 |
+
|
33 |
+
|
34 |
+
if __name__ == "__main__":
|
35 |
+
args = parse_args()
|
36 |
+
llm = LLM(model=args.base_model, tensor_parallel_size=args.n_gpus)
|
37 |
+
gr.ChatInterface(
|
38 |
+
predict,
|
39 |
+
title="LLM playground - WizardLM-13B-V1.2",
|
40 |
+
description="This is a LLM playground for WizardLM-13B-V1.2, github: https://github.com/nlpxucan/WizardLM, huggingface: https://huggingface.co/WizardLM",
|
41 |
+
theme="soft",
|
42 |
+
chatbot=gr.Chatbot(height=1400, label="Chat History",),
|
43 |
+
textbox=gr.Textbox(placeholder="input", container=False, scale=7),
|
44 |
+
retry_btn=None,
|
45 |
+
undo_btn="Delete Previous",
|
46 |
+
clear_btn="Clear",
|
47 |
+
additional_inputs=[
|
48 |
+
gr.Textbox("A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.", label="System Prompt"),
|
49 |
+
gr.Slider(0, 1, 0.9, label="Temperature"),
|
50 |
+
gr.Slider(100, 2048, 1024, label="Max Tokens"),
|
51 |
+
],
|
52 |
+
additional_inputs_accordion_name="Parameters",
|
53 |
+
).queue().launch(share=False, server_port=7870)
|