FreshBench / app.py
lab_PC
rm lm harness
b58280d
raw
history blame
4.67 kB
# import gradio as gr
# from transformers import AutoTokenizer
# # 第一个功能:基于输入文本和对应的损失值对文本进行着色展示
# def color_text(text_list=["hi", "FreshEval"], loss_list=[0.1,0.7]):
# """
# 根据损失值为文本着色。
# """
# highlighted_text = []
# for text, loss in zip(text_list, loss_list):
# # color = "#FF0000" if float(loss) > 0.5 else "#00FF00"
# color=loss
# highlighted_text.append({"text": text, "bg_color": color})
# return gr.HighlightedText(highlighted_text).get_html()
# # 第二个功能:根据 ID 列表和 tokenizer 将 ID 转换为文本,并展示
# def get_text(ids_list=[0.1,0.7], tokenizer=None):
# """
# 给定一个 ID 列表和 tokenizer 名称,将这些 ID 转换成文本。
# """
# return ['Hi', 'Adam']
# # tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
# # text = tokenizer.decode(eval(ids_list), skip_special_tokens=True)
# # 这里只是简单地返回文本,但是可以根据实际需求添加颜色或其他样式
# # return text
# def get_ids_loss(text, tokenizer, model):
# """
# 给定一个文本,返回其对应的 IDs 和损失值。
# """
# # tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
# # model = AutoModelForCausalLM.from_pretrained(model_name)
# # 这里只是简单地返回 IDs 和损失值,但是可以根据实际需求添加颜色或其他样式
# return [1, 2], [0.1, 0.7]
# def color_pipeline(text=["hi", "FreshEval"], model=None):
# """
# 给定一个文本,返回其对应的着色文本。
# """
# tokenizer=None
# ids, loss = get_ids_loss(text, tokenizer, model)
# text = get_text(ids, tokenizer)
# return color_text(text, loss)
# # 创建 Gradio 界面
# with gr.Blocks() as demo:
# with gr.Tab("color your text"):
# with gr.Row():
# text_input = gr.Textbox(label="input text", placeholder="input your text here...")
# # loss_input = gr.Number(label="loss")
# model_input = gr.Textbox(label="model name", placeholder="input your model name here...")
# color_text_output = gr.HTML(label="colored text")
# gr.Markdown("## Text Examples")
# # gr.Examples(
# # [["hi", "Adam"], [0.1,0.7]],
# # [text_input, loss_input],
# # cache_examples=True,
# # fn=color_text,
# # outputs=color_text_output
# # )
# color_text_button = gr.Button("color the text").click(color_pipeline, inputs=[text_input, model_input], outputs=color_text_output)
# date_time_input = gr.Textbox(label="the date when the text is generated")#TODO add date time input
# description_input = gr.Textbox(label="description of the text")
# submit_button = gr.Button("submit a post or record")
# #TODO add model and its score
# # with gr.Tab("ID 转文本展示"):
# # with gr.Row():
# # ids_input = gr.Textbox(label="输入 IDs (如 [101, 102, ...])")
# # tokenizer_input = gr.Textbox(label="Tokenizer 名称", value="bert-base-uncased")
# # show_text_output = gr.Textbox(label="转换后的文本")
# # show_text_button = gr.Button("转换并展示").click(show_text, inputs=[ids_input, tokenizer_input], outputs=show_text_output)
# with gr.Tab("model ppl with time"):
# '''
# see the matplotlib example, to see ppl with time, select the models
# '''
# with gr.Tab("model ppl with time"):
# '''
# see the matplotlib example, to see ppl with time, select the models
# '''
# demo.launch()
# import gradio as gr
# from transformers import pipeline
# pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
# def predict(input_img):
# predictions = pipeline(input_img)
# return input_img, {p["label"]: p["score"] for p in predictions}
# gradio_app = gr.Interface(
# predict,
# inputs=gr.Image(label="Select hot dog candidate", sources=['upload', 'webcam'], type="pil"),
# outputs=[gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=2)],
# title="Hot Dog? Or Not?",
# )
# if __name__ == "__main__":
# gradio_app.launch()
import gradio as gr
def greet(name, intensity):
return "Hello, " + name + "!" * int(intensity)
demo = gr.Interface(
fn=greet,
inputs=["text", "slider"],
outputs=["text"],
)
demo.launch(debug=True)
# lm-eval
# lm-evaluation-harness