Spaces:
Build error
Build error
lab_PC
commited on
Commit
·
df513ba
1
Parent(s):
968cdfb
test_remote
Browse files- __pycache__/app.cpython-37.pyc +0 -0
- app.py +129 -0
- requirements.txt +3 -0
__pycache__/app.cpython-37.pyc
ADDED
|
Binary file (422 Bytes). View file
|
|
|
app.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# import gradio as gr
|
| 2 |
+
# from transformers import AutoTokenizer
|
| 3 |
+
|
| 4 |
+
# # 第一个功能:基于输入文本和对应的损失值对文本进行着色展示
|
| 5 |
+
# def color_text(text_list=["hi", "FreshEval"], loss_list=[0.1,0.7]):
|
| 6 |
+
# """
|
| 7 |
+
# 根据损失值为文本着色。
|
| 8 |
+
# """
|
| 9 |
+
# highlighted_text = []
|
| 10 |
+
# for text, loss in zip(text_list, loss_list):
|
| 11 |
+
# # color = "#FF0000" if float(loss) > 0.5 else "#00FF00"
|
| 12 |
+
# color=loss
|
| 13 |
+
# highlighted_text.append({"text": text, "bg_color": color})
|
| 14 |
+
# return gr.HighlightedText(highlighted_text).get_html()
|
| 15 |
+
|
| 16 |
+
# # 第二个功能:根据 ID 列表和 tokenizer 将 ID 转换为文本,并展示
|
| 17 |
+
# def get_text(ids_list=[0.1,0.7], tokenizer=None):
|
| 18 |
+
# """
|
| 19 |
+
# 给定一个 ID 列表和 tokenizer 名称,将这些 ID 转换成文本。
|
| 20 |
+
# """
|
| 21 |
+
# return ['Hi', 'Adam']
|
| 22 |
+
# # tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
|
| 23 |
+
# # text = tokenizer.decode(eval(ids_list), skip_special_tokens=True)
|
| 24 |
+
# # 这里只是简单地返回文本,但是可以根据实际需求添加颜色或其他样式
|
| 25 |
+
# # return text
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# def get_ids_loss(text, tokenizer, model):
|
| 29 |
+
# """
|
| 30 |
+
# 给定一个文本,返回其对应的 IDs 和损失值。
|
| 31 |
+
# """
|
| 32 |
+
# # tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
|
| 33 |
+
# # model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 34 |
+
# # 这里只是简单地返回 IDs 和损失值,但是可以根据实际需求添加颜色或其他样式
|
| 35 |
+
# return [1, 2], [0.1, 0.7]
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# def color_pipeline(text=["hi", "FreshEval"], model=None):
|
| 39 |
+
# """
|
| 40 |
+
# 给定一个文本,返回其对应的着色文本。
|
| 41 |
+
# """
|
| 42 |
+
# tokenizer=None
|
| 43 |
+
# ids, loss = get_ids_loss(text, tokenizer, model)
|
| 44 |
+
# text = get_text(ids, tokenizer)
|
| 45 |
+
# return color_text(text, loss)
|
| 46 |
+
|
| 47 |
+
# # 创建 Gradio 界面
|
| 48 |
+
# with gr.Blocks() as demo:
|
| 49 |
+
# with gr.Tab("color your text"):
|
| 50 |
+
# with gr.Row():
|
| 51 |
+
# text_input = gr.Textbox(label="input text", placeholder="input your text here...")
|
| 52 |
+
# # loss_input = gr.Number(label="loss")
|
| 53 |
+
# model_input = gr.Textbox(label="model name", placeholder="input your model name here...")
|
| 54 |
+
# color_text_output = gr.HTML(label="colored text")
|
| 55 |
+
# gr.Markdown("## Text Examples")
|
| 56 |
+
# # gr.Examples(
|
| 57 |
+
# # [["hi", "Adam"], [0.1,0.7]],
|
| 58 |
+
# # [text_input, loss_input],
|
| 59 |
+
# # cache_examples=True,
|
| 60 |
+
# # fn=color_text,
|
| 61 |
+
# # outputs=color_text_output
|
| 62 |
+
# # )
|
| 63 |
+
# color_text_button = gr.Button("color the text").click(color_pipeline, inputs=[text_input, model_input], outputs=color_text_output)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# date_time_input = gr.Textbox(label="the date when the text is generated")#TODO add date time input
|
| 67 |
+
# description_input = gr.Textbox(label="description of the text")
|
| 68 |
+
# submit_button = gr.Button("submit a post or record")
|
| 69 |
+
# #TODO add model and its score
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# # with gr.Tab("ID 转文本展示"):
|
| 73 |
+
# # with gr.Row():
|
| 74 |
+
# # ids_input = gr.Textbox(label="输入 IDs (如 [101, 102, ...])")
|
| 75 |
+
# # tokenizer_input = gr.Textbox(label="Tokenizer 名称", value="bert-base-uncased")
|
| 76 |
+
# # show_text_output = gr.Textbox(label="转换后的文本")
|
| 77 |
+
# # show_text_button = gr.Button("转换并展示").click(show_text, inputs=[ids_input, tokenizer_input], outputs=show_text_output)
|
| 78 |
+
|
| 79 |
+
# with gr.Tab("model ppl with time"):
|
| 80 |
+
# '''
|
| 81 |
+
# see the matplotlib example, to see ppl with time, select the models
|
| 82 |
+
# '''
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
# with gr.Tab("model ppl with time"):
|
| 86 |
+
# '''
|
| 87 |
+
# see the matplotlib example, to see ppl with time, select the models
|
| 88 |
+
# '''
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
# demo.launch()
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
# import gradio as gr
|
| 97 |
+
# from transformers import pipeline
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
# pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
|
| 101 |
+
|
| 102 |
+
# def predict(input_img):
|
| 103 |
+
# predictions = pipeline(input_img)
|
| 104 |
+
# return input_img, {p["label"]: p["score"] for p in predictions}
|
| 105 |
+
|
| 106 |
+
# gradio_app = gr.Interface(
|
| 107 |
+
# predict,
|
| 108 |
+
# inputs=gr.Image(label="Select hot dog candidate", sources=['upload', 'webcam'], type="pil"),
|
| 109 |
+
# outputs=[gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=2)],
|
| 110 |
+
# title="Hot Dog? Or Not?",
|
| 111 |
+
# )
|
| 112 |
+
|
| 113 |
+
# if __name__ == "__main__":
|
| 114 |
+
# gradio_app.launch()
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
import gradio as gr
|
| 119 |
+
|
| 120 |
+
def greet(name, intensity):
|
| 121 |
+
return "Hello, " + name + "!" * int(intensity)
|
| 122 |
+
|
| 123 |
+
demo = gr.Interface(
|
| 124 |
+
fn=greet,
|
| 125 |
+
inputs=["text", "slider"],
|
| 126 |
+
outputs=["text"],
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
demo.launch(debug=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
lm-evaluation-harness
|
| 2 |
+
transformers
|
| 3 |
+
torch
|