vtrv.vls commited on
Commit
01af800
1 Parent(s): 7be9d95

Arena test

Browse files
Files changed (2) hide show
  1. app.py +14 -2
  2. models.py +23 -0
app.py CHANGED
@@ -3,21 +3,33 @@ import argparse
3
  import os
4
 
5
  from utils import generate
 
6
  from constants import css, js_code, js_light
7
 
8
  MERA_table = None
 
9
 
10
- def gen(content):
11
  res = generate(content,'auth_token.json')
12
  return res
13
 
 
 
 
 
14
  def tab_arena():
15
- gradio.Interface(fn=gen, inputs="text", outputs="text") # arena =
 
 
 
 
 
16
  # arena.launch()
17
 
18
  with open("test.md", "r") as f:
19
  TEST_MD = f.read()
20
 
 
21
 
22
  def build_demo():
23
  # global original_dfs, available_models, gpt4t_dfs, haiku_dfs, llama_dfs
 
3
  import os
4
 
5
  from utils import generate
6
+ from models import get_tiny_llama, response_tiny_llama
7
  from constants import css, js_code, js_light
8
 
9
  MERA_table = None
10
+ TINY_LLAMA = get_tiny_llama()
11
 
12
+ def giga_gen(content):
13
  res = generate(content,'auth_token.json')
14
  return res
15
 
16
+ def tiny_gen(content):
17
+ res = response_tiny_llama(TINY_LLAMA, content)
18
+ return res
19
+
20
  def tab_arena():
21
+ with gradio.Row():
22
+ with gradio.Column():
23
+ gradio.Interface(fn=giga_gen, inputs="text", outputs="text", allow_flagging=False, title='Giga') # arena =
24
+ with gradio.Column():
25
+ gradio.Interface(fn=tiny_gen, inputs="text", outputs="text", allow_flagging=False, title='TinyLlama') # arena =
26
+
27
  # arena.launch()
28
 
29
  with open("test.md", "r") as f:
30
  TEST_MD = f.read()
31
 
32
+ available_models = ["GigaChat", ""] # list(model_info.keys())
33
 
34
  def build_demo():
35
  # global original_dfs, available_models, gpt4t_dfs, haiku_dfs, llama_dfs
models.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import pipeline
3
+
4
+ def get_tiny_llama():
5
+ pipe = pipeline("text-generation", model="TinyLlama/TinyLlama-1.1B-Chat-v1.0", torch_dtype=torch.float16, device_map="auto")
6
+ return pipe
7
+
8
+ def response_tiny_llama(
9
+ pipe=None,
10
+ content="How many helicopters can a human eat in one sitting?"
11
+ ):
12
+ # We use the tokenizer's chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating
13
+ messages = [
14
+ {
15
+ "role": "system",
16
+ "content": "You are a friendly chatbot who always responds in the style of a pirate",
17
+ },
18
+ {"role": "user", "content": content},
19
+ ]
20
+ prompt = pipe.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
21
+ outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
22
+
23
+ return outputs[0]['generated_text']