Spaces:
Sleeping
Sleeping
File size: 8,943 Bytes
1639c46 bac027d 014ba5e c03435f 9540a56 f39aadc 014ba5e 7028ba1 1639c46 6f92fa3 1639c46 1847ea5 014ba5e 7f3196a deb74eb 7815cda deb74eb e7d646f bd30708 f39aadc 7f3196a 2375d69 c84ae80 2375d69 e7d646f bd30708 cce3c9c 6f92fa3 8c11891 59904b9 451712e ce0391b 1847ea5 8c11891 409cbac 451712e 409cbac 451712e 409cbac 8c11891 451712e 9540a56 451712e 9540a56 451712e 6934609 99cc45f 6f92fa3 1639c46 01af800 7496919 cce3c9c 01af800 7496919 cce3c9c 65408a7 cce3c9c df22c76 4bea324 8c11891 8586e70 df22c76 8c11891 65408a7 5d15a5a d629b6c df22c76 8c11891 cce3c9c 01af800 7be9d95 1639c46 c03435f d8ef990 c03435f d8ef990 8f4c6d6 d8ef990 8f4c6d6 d8ef990 8f4c6d6 d8ef990 c03435f 1692b33 1639c46 01af800 1639c46 7be9d95 1639c46 c03435f 1639c46 7be9d95 1639c46 4d068a9 2375d69 7028ba1 014ba5e 9e16c0f 014ba5e 7be9d95 1639c46 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
import gradio
import argparse
import os
import boto3
from datetime import datetime
import pandas as pd
from copy import copy
from utils import generate, send_to_s3
from models import get_tinyllama, get_qwen2ins1b, response_tinyllama, response_qwen2ins1b
from constants import css, js_code, js_light
MERA_table = None
TINYLLAMA = None
QWEN2INS1B = None
RIGHT_MODEL = None
LEFT_MODEL = None
S3_SESSION = None
def giga_gen(content, chat_history):
chat_history.append([content])
res = generate(chat_history,'auth_token.json')
chat_history[-1].append(res)
send_to_s3(res, f'protobench/giga_{str(datetime.now()).replace(" ", "_")}.json', S3_SESSION)
return '', chat_history
def tiny_gen(content, chat_history):
chat_history.append([content])
res = response_tinyllama(TINY_LLAMA, chat_history)
chat_history[-1].append(res)
send_to_s3(res, f'protobench/tiny_{str(datetime.now()).replace(" ", "_")}.json', S3_SESSION)
return '', chat_history
def qwen_gen(content, chat_history):
chat_history.append([content])
res = response_qwen2ins1b(QWEN2INS1B, chat_history)
chat_history[-1].append(res)
send_to_s3(res, f'protobench/tiny_{str(datetime.now()).replace(" ", "_")}.json', S3_SESSION)
return '', chat_history
def model_gen(content, chat_history, model_type: str):
if content is None:
return '', []
if len(content) == 0:
return '', []
gen = MODEL_LIB[model_type]
return gen(content, chat_history)
def model_regen(content, chat_history, model_type: str):
if chat_history is None:
return '', []
if len(chat_history) == 0:
return '', []
gen = MODEL_LIB[model_type]
msg = copy(chat_history[-1][0])
return gen(msg, chat_history[:-1])
def clear_chat():
return '', []
MODEL_LIB = {'RUBASE': giga_gen, 'TINYLLAMA': tiny_gen, 'QWEN2INS1B': qwen_gen}
def tab_arena():
with gradio.Row():
with gradio.Column():
model_left = gradio.Dropdown(["TINYLLAMA", "QWEN2INS1B", "RUBASE"], value="TINYLLAMA", interactive=True, multiselect=False, label="Left model")
chatbot_left = gradio.Chatbot()
with gradio.Column():
model_right = gradio.Dropdown(["TINYLLAMA", "QWEN2INS1B", "RUBASE"], value= "RUBASE", interactive=True, multiselect=False, label="Right model")
chatbot_right = gradio.Chatbot()
with gradio.Row():
msg = gradio.Textbox(label='Prompt', placeholder='Put your prompt here')
with gradio.Row():
gradio.Button('Both Good')
gradio.Button('Left Better')
gradio.Button('Right Better')
gradio.Button('Both Bad')
with gradio.Row():
with gradio.Accordion("Parameters", open=False):
context = gradio.Checkbox(label="No context", value=False)
top_p = gradio.Slider(label='Top P', minimum=0, maximum=1, value=1, step=0.05, interactive=True)
temp = gradio.Slider(label='Temperature', minimum=0, maximum=1, value=0.7, step=0.05, interactive=True)
max_tokens = gradio.Slider(label='Max ouput tokens', minimum=1, maximum=2048, value=512, step=1, interactive=True)
with gradio.Row():
clear = gradio.ClearButton([msg, chatbot_left, chatbot_right], value='Clear history')
regen_left = gradio.Button(value='Regenerate left answer')
regen_right = gradio.Button(value='Regenerate right answer')
regen_left.click(model_regen, [msg, chatbot_left, model_left], [msg, chatbot_left])
regen_right.click(model_regen, [msg, chatbot_right, model_right], [msg, chatbot_right])
with gradio.Blocks():
model_left.change(clear_chat, [], [msg, chatbot_left])
model_right.change(clear_chat, [], [msg, chatbot_right])
msg.submit(model_gen, [msg, chatbot_left, model_left], [msg, chatbot_left])
msg.submit(model_gen, [msg, chatbot_right, model_right], [msg, chatbot_right])
# with gradio.Column():
# gradio.ChatInterface(
# fn=giga_gen,
# examples=[{"text": "hello"}, {"text": "hola"}, {"text": "merhaba"}],
# title="Giga",
# multimodal=True,
# )
# with gradio.Column():
# gradio.ChatInterface(
# fn=tiny_gen,
# examples=[{"text": "hello"}, {"text": "hola"}, {"text": "merhaba"}],
# title="Tiny",
# multimodal=True,
# )
# with gradio.Column():
# gradio.Interface(fn=giga_gen, inputs="text", outputs="text", allow_flagging=False, title='Giga') # arena =
# with gradio.Column():
# gradio.Interface(fn=tiny_gen, inputs="text", outputs="text", allow_flagging=False, title='TinyLlama') # arena =
# arena.launch()
def tab_leaderboard():
df = pd.DataFrame({
"Model" : ['A', 'B', 'C',],
"Test 1" : [0, 1, 0],
"Test 2" : [1, 0, 1,],
})
# Function to apply text color
def highlight_cols(x):
df = x.copy()
# df.loc[:, :] = 'color: purple'
df[['Model']] = 'color: green'
return df
# Applying the style function
# s = df.style.apply(highlight_cols, axis = None)
# Displaying the styled dataframe in Gradio
with gradio.TabItem("Autogen Metrics", elem_id="od-benchmark-tab-table-ablation", id=0, elem_classes="subtab"):
with gradio.Blocks() as demo:
gradio.DataFrame(df)
with gradio.TabItem("Autometrics", elem_id="od-benchmark-tab-table-ablation", id=1, elem_classes="subtab"):
with gradio.Blocks() as demo:
gradio.DataFrame(df)
with gradio.TabItem("SBS metrics", elem_id="od-benchmark-tab-table-ablation", id=2, elem_classes="subtab"):
with gradio.Blocks() as demo:
gradio.DataFrame(df)
with gradio.TabItem("Arena ELO rating", elem_id="od-benchmark-tab-table-ablation", id=3, elem_classes="subtab"):
with gradio.Blocks() as demo:
gradio.DataFrame(df)
with open("test.md", "r") as f:
TEST_MD = f.read()
available_models = ["GigaChat", ""] # list(model_info.keys())
def build_demo():
# global original_dfs, available_models, gpt4t_dfs, haiku_dfs, llama_dfs
with gradio.Blocks(theme=gradio.themes.Base(), css=css, js=js_light) as demo:
# gradio.HTML(BANNER, elem_id="banner")
# gradio.Markdown(HEADER_MD.replace("{model_num}", str(len(original_dfs["-1"]))), elem_classes="markdown-text")
with gradio.Tabs(elem_classes="tab-buttons") as tabs:
with gradio.TabItem("πΌ MERA leaderboard", elem_id="od-benchmark-tab-table", id=0):
gradio.Markdown(TEST_MD, elem_classes="markdown-text-details")
tab_leaderboard()
with gradio.TabItem("π SBS by categories and criteria", elem_id="od-benchmark-tab-table", id=1):
gradio.Markdown(TEST_MD, elem_classes="markdown-text-details")
with gradio.TabItem("π₯ Model arena", elem_id="od-benchmark-tab-table", id=2):
tab_arena()
# _tab_explore()
with gradio.TabItem("πͺ About MERA", elem_id="od-benchmark-tab-table", id=3):
gradio.Markdown(TEST_MD, elem_classes="markdown-text")
# gr.Markdown(f"Last updated on **{LAST_UPDATED}** | [Link to V1-legacy](https://huggingface.co/spaces/allenai/WildBench-V1-legacy)", elem_classes="markdown-text-small")
# with gr.Row():
# with gr.Accordion("π Citation", open=False, elem_classes="accordion-label"):
# gr.Textbox(
# value=CITATION_TEXT,
# lines=7,
# label="Copy the BibTeX snippet to cite this source",
# elem_id="citation-button",
# show_copy_button=True)
# ).style(show_copy_button=True)
return demo
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--share", action="store_true")
# parser.add_argument("--bench_table", help="Path to MERA table", default="data_dir/MERA_jun2024.jsonl")
args = parser.parse_args()
# data_load(args.result_file)
# TYPES = ["number", "markdown", "number"]
TINY_LLAMA = get_tinyllama()
QWEN2INS1B = get_qwen2ins1b()
try:
session = boto3.session.Session()
S3_SESSION = session.client(
service_name='s3',
endpoint_url=os.getenv('S3_ENDPOINT'),
aws_access_key_id=os.getenv('S3_ACCESS_KEY'),
aws_secret_access_key=os.getenv('S3_SECRET_KEY'),
)
except:
print('Failed to start s3 session')
demo = build_demo()
demo.launch(share=args.share, height=3000, width="110%") # share=args.share
# demo = gradio.Interface(fn=gen, inputs="text", outputs="text")
# demo.launch()
|