nroggendorff commited on
Commit
b7d4c4e
·
verified ·
1 Parent(s): b0f4d21

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -19
app.py CHANGED
@@ -1,26 +1,14 @@
1
  import gradio as gr
2
- from transformers import AutoModelForCausalLM, AutoTokenizer
3
 
4
- tokenizer = AutoTokenizer.from_pretrained('stabilityai/stablelm-2-zephyr-1_6b')
5
- model = AutoModelForCausalLM.from_pretrained(
6
- 'stabilityai/stablelm-2-zephyr-1_6b',
7
- device_map="auto"
8
- )
9
 
10
  def pipe(text: str):
11
- tokens = model.generate(
12
- inputs.to(model.device),
13
- max_new_tokens=1024,
14
- temperature=0.5,
15
- do_sample=True
16
- )
17
-
18
- inputs = tokenizer.apply_chat_template(
19
- text,
20
- add_generation_prompt=True,
21
- return_tensors='pt'
22
- )
23
- return tokenizer.decode(tokens[0], skip_special_tokens=False)
24
 
25
  if __name__ == "__main__":
26
  interface = gr.Interface(pipe, gr.Textbox(label="Prompt"), gr.Textbox(label="Response"), title="Text Completion")
 
1
  import gradio as gr
2
+ from vllm import LLM, SamplingParams
3
 
4
+ llm = LLM(model="meta-llama/Llama-2-7B-Chat-hf")
5
+ sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
 
 
 
6
 
7
  def pipe(text: str):
8
+ prompt = [text]
9
+ tokens = llm.generate(prompt, sampling_params)
10
+ output = (output.outputs[0].text for output in tokens)
11
+ return output[0]
 
 
 
 
 
 
 
 
 
12
 
13
  if __name__ == "__main__":
14
  interface = gr.Interface(pipe, gr.Textbox(label="Prompt"), gr.Textbox(label="Response"), title="Text Completion")