Locutusque commited on
Commit
8bd462e
·
verified ·
1 Parent(s): 039e0cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -3
app.py CHANGED
@@ -1,7 +1,8 @@
1
  import gradio as gr
2
- from transformers import pipeline, AutoTokenizer
3
  import torch
4
  import spaces
 
5
  import os
6
 
7
  @spaces.GPU
@@ -23,8 +24,15 @@ def generate(
23
  prompt = user_input
24
  else:
25
  prompt = f"<|im_start|>system\nYou are an AI assistant that follows instruction extremely well. Help as much as you can.<|im_end|>\n<|im_start|>user\n{user_input}<|im_end|>\n<|im_start|>assistant\n"
26
- outputs = pipe(prompt, max_new_tokens=max_new_tokens, do_sample=True,
27
- temperature=temperature, top_k=top_k, top_p=top_p, repetition_penalty=1.1)
 
 
 
 
 
 
 
28
  return outputs[0]["generated_text"]
29
 
30
  model_choices = ["M4-ai/Hercules-Mini-1.8B", "Locutusque/Hyperion-3.0-Mistral-7B-DPO", "Locutusque/OpenCerebrum-1.5-Mistral-11B-Evolved-beta", "M4-ai/tau-1.8B", "Locutusque/OpenCerebrum-1.5-Mistral-7b-v0.2-alpha", "Locutusque/Hercules-4.0-Mistral-v0.2-7B", "Locutusque/Hercules-3.1-Mistral-7B"]
 
1
  import gradio as gr
2
+ from transformers import pipeline, AutoTokenizer, TextIteratorStreamer
3
  import torch
4
  import spaces
5
+ from threading import Thread
6
  import os
7
 
8
  @spaces.GPU
 
24
  prompt = user_input
25
  else:
26
  prompt = f"<|im_start|>system\nYou are an AI assistant that follows instruction extremely well. Help as much as you can.<|im_end|>\n<|im_start|>user\n{user_input}<|im_end|>\n<|im_start|>assistant\n"
27
+ streamer = TextIteratorStreamer(tokenizer, timeout=240.0, skip_prompt=True, skip_special_tokens=True)
28
+ generation_kwargs = dict(text_inputs=prompt, streamer=streamer, max_new_tokens=max_new_tokens, do_sample=True, top_p=top_p, top_k=top_k,
29
+ temperature=temperature, num_beams=1, repetition_penalty=repetition_penalty, eos_token_id=pipe.tokenizer.eos_token_id)
30
+ t = Thread(target=pipe.__call__, kwargs=generation_kwargs)
31
+ t.start()
32
+ outputs = []
33
+ for chunk in streamer:
34
+ outputs.append(chunk)
35
+ yield "".join(outputs)
36
  return outputs[0]["generated_text"]
37
 
38
  model_choices = ["M4-ai/Hercules-Mini-1.8B", "Locutusque/Hyperion-3.0-Mistral-7B-DPO", "Locutusque/OpenCerebrum-1.5-Mistral-11B-Evolved-beta", "M4-ai/tau-1.8B", "Locutusque/OpenCerebrum-1.5-Mistral-7b-v0.2-alpha", "Locutusque/Hercules-4.0-Mistral-v0.2-7B", "Locutusque/Hercules-3.1-Mistral-7B"]