tREeFrOGorigami commited on
Commit
5e1514b
1 Parent(s): b58280d
__pycache__/hello_test.cpython-310.pyc ADDED
Binary file (431 Bytes). View file
 
app.py CHANGED
@@ -1,132 +1,178 @@
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)
130
 
131
- # lm-eval
132
- # lm-evaluation-harness
 
1
+ import gradio as gr
2
+ import os
3
  # from transformers import AutoTokenizer
4
+ os.system('git clone https://github.com/EleutherAI/lm-evaluation-harness')
5
+ os.system('cd lm-evaluation-harness')
6
+ os.system('pip install -e .')
7
+ # 第一个功能:基于输入文本和对应的损失值对文本进行着色展示
8
+ def color_text(text_list=["hi", "FreshEval"], loss_list=[0.1,0.7]):
9
+ """
10
+ 根据损失值为文本着色。
11
+ """
12
+ highlighted_text = []
13
+ for text, loss in zip(text_list, loss_list):
14
+ # color = "#FF0000" if float(loss) > 0.5 else "#00FF00"
15
+ color=loss
16
+ # highlighted_text.append({"text": text, "bg_color": color})
17
+ highlighted_text.append((text, color))
18
+
19
+ print(highlighted_text)
20
+ return highlighted_text
21
+
22
+ # 第二个功能:根据 ID 列表和 tokenizer 将 ID 转换为文本,并展示
23
+ def get_text(ids_list=[0.1,0.7], tokenizer=None):
24
+ """
25
+ 给定一个 ID 列表和 tokenizer 名称,将这些 ID 转换成文本。
26
+ """
27
+ return ['Hi', 'Adam']
28
+ # tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
29
+ # text = tokenizer.decode(eval(ids_list), skip_special_tokens=True)
30
+ # 这里只是简单地返回文本,但是可以根据实际需求添加颜色或其他样式
31
+ # return text
32
+
33
+
34
+ def get_ids_loss(text, tokenizer, model):
35
+ """
36
+ 给定一个文本,model and its tokenizer,返回其对应的 IDs 和损失值。
37
+ """
38
+ # tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
39
+ # model = AutoModelForCausalLM.from_pretrained(model_name)
40
+ # 这里只是简单地返回 IDs 和损失值,但是可以根据实际需求添加颜色或其他样式
41
+ return [1, 2], [0.1, 0.7]
42
+
43
+
44
+ def color_pipeline(text=["hi", "FreshEval"], model=None):
45
+ """
46
+ 给定一个文本,返回其对应的着色文本。
47
+ """
48
+ tokenizer=None # get tokenizer
49
+ ids, loss = get_ids_loss(text, tokenizer, model)
50
+ text = get_text(ids, tokenizer)
51
+ return color_text(text, loss)
52
+
53
+
54
+ # TODO can this be global ? maybe need session to store info of the user
55
+
56
+ # 创建 Gradio 界面
57
+ with gr.Blocks() as demo:
58
+ with gr.Tab("color your text"):
59
+ with gr.Row():
60
+ text_input = gr.Textbox(label="input text", placeholder="input your text here...")
61
+ # TODO craw and drop the file
62
+
63
+ # loss_input = gr.Number(label="loss")
64
+ model_input = gr.Textbox(label="model name", placeholder="input your model name here...")
65
+ # TODO select models that can be used online
66
+ # TODO maybe add our own models
67
+
68
+
69
+ color_text_output = gr.HTML(label="colored text")
70
+ # gr.Markdown("## Text Examples")
71
+ # gr.Examples(
72
+ # [["hi", "Adam"], [0.1,0.7]],
73
+ # [text_input, loss_input],
74
+ # cache_examples=True,
75
+ # fn=color_text,
76
+ # outputs=color_text_output
77
+ # )
78
+ color_text_button = gr.Button("color the text").click(color_pipeline, inputs=[text_input, model_input], outputs=gr.HighlightedText(label="colored text"))
79
+
80
+
81
+ date_time_input = gr.Textbox(label="the date when the text is generated")#TODO add date time input
82
+ description_input = gr.Textbox(label="description of the text")
83
+ submit_button = gr.Button("submit a post or record").click()
84
+ #TODO add model and its score
85
+
86
+ with gr.Tab('test your qeustion'):
87
+ '''
88
+ use extract, or use ppl
89
+ '''
90
+ question=gr.Textbox(placeholder='input your question here...')
91
+ answer=gr.Textbox(placeholder='input your answer here...')
92
+ other_choices=gr.Textbox(placeholder='input your other choices here...')
93
 
94
+ test_button=gr.Button('test').click()
95
+ #TODO add the model and its score
96
 
97
+ def test_question(question, answer, other_choices):
98
+ '''
99
+ use extract, or use ppl
100
+ '''
101
+ answer_ppl, other_choices_ppl = get_ppl(question, answer, other_choices)
102
+ return answer_ppl, other_choices_ppl
103
 
104
 
105
 
106
+ with gr.Tab("model text ppl with time"):
107
+ '''
108
+ see the matplotlib example, to see ppl with time, select the models
109
+ '''
110
+ # load the json file with time,
111
 
112
+
113
+ with gr.Tab("model quesion acc with time"):
114
+ '''
115
+ see the matplotlib example, to see ppl with time, select the models
116
+ '''
117
+ #
118
+
119
+
120
+ with gr.Tab("hot questions"):
121
+ '''
122
+ see the questions and answers
123
+ '''
124
+ with gr.Tab("ppl"):
125
+ '''
126
+ see the questions
127
+ '''
128
+
129
 
130
+ demo.launch(debug=True)
 
 
 
 
131
 
 
 
 
 
 
 
132
 
 
 
133
 
134
 
135
 
136
+ # import gradio as gr
137
+ # import os
138
+ # os.system('python -m spacy download en_core_web_sm')
139
+ # import spacy
140
+ # from spacy import displacy
141
+
142
+ # nlp = spacy.load("en_core_web_sm")
143
+
144
+ # def text_analysis(text):
145
+ # doc = nlp(text)
146
+ # html = displacy.render(doc, style="dep", page=True)
147
+ # html = (
148
+ # "<div style='max-width:100%; max-height:360px; overflow:auto'>"
149
+ # + html
150
+ # + "</div>"
151
+ # )
152
+ # pos_count = {
153
+ # "char_count": len(text),
154
+ # "token_count": 0,
155
+ # }
156
+ # pos_tokens = []
157
+
158
+ # for token in doc:
159
+ # pos_tokens.extend([(token.text, token.pos_), (" ", None)])
160
+
161
+ # return pos_tokens, pos_count, html
162
+
163
+ # demo = gr.Interface(
164
+ # text_analysis,
165
+ # gr.Textbox(placeholder="Enter sentence here..."),
166
+ # ["highlight", "json", "html"],
167
+ # examples=[
168
+ # ["What a beautiful morning for a walk!"],
169
+ # ["It was the best of times, it was the worst of times."],
170
+ # ],
171
+ # )
172
 
173
+ # demo.launch()
 
174
 
 
 
 
 
 
175
 
 
176
 
177
+ # # lm-eval
178
+ # # lm-evaluation-harness
diff_color.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from difflib import Differ
3
+
4
+ import gradio as gr
5
+
6
+
7
+ def diff_texts(text1, text2):
8
+ d = Differ()
9
+ rtn =[
10
+ (token[2:], token[0] if token[0] != " " else None)
11
+ for token in d.compare(text1, text2)
12
+ ]
13
+ print(rtn)
14
+ return rtn
15
+
16
+
17
+ demo = gr.Interface(
18
+ diff_texts,
19
+ [
20
+ gr.Textbox(
21
+ label="Text 1",
22
+ info="Initial text",
23
+ lines=3,
24
+ value="The quick brown fox jumped over the lazy dogs.",
25
+ ),
26
+ gr.Textbox(
27
+ label="Text 2",
28
+ info="Text to compare",
29
+ lines=3,
30
+ value="The fast brown fox jumps over lazy dogs.",
31
+ ),
32
+ ],
33
+ gr.HighlightedText(
34
+ label="Diff",
35
+ combine_adjacent=True,
36
+ show_legend=True,
37
+ color_map={"+": "red", "-": "green"}),
38
+ theme=gr.themes.Base()# the return is here
39
+ )
40
+ if __name__ == "__main__":
41
+ demo.launch()
42
+
flagged/log.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ Text 1,Text 2,Diff,flag,username,timestamp
2
+ The quick brown fox jumped over the lazy dogs.,The fast brown fox jumps over lazy dogs.,,,,2024-03-13 16:50:01.853095
hello_test.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def greet(name, intensity):
4
+ return "Hello, " + name + ",,!" * int(intensity)
5
+ # return "Hello, " + name + ",,!" * int(0/int(intensity))# you can see the bug in command line
6
+
7
+ demo = gr.Interface(
8
+ fn=greet,
9
+ inputs=["text", "slider"],
10
+ outputs=["text"],
11
+ )
12
+
13
+ demo.launch(debug=True)
hf_space_test.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # this need hugginface connection
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+
6
+ pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
7
+
8
+ def predict(input_img):
9
+ predictions = pipeline(input_img)
10
+ return input_img, {p["label"]: p["score"] for p in predictions}
11
+
12
+ gradio_app = gr.Interface(
13
+ predict,
14
+ inputs=gr.Image(label="Select hot dog candidate", sources=['upload', 'webcam'], type="pil"),
15
+ outputs=[gr.Image(label="Processed Image"), gr.Label(label="Result", num_top_classes=2)],
16
+ title="Hot Dog? Or Not?",
17
+ )
18
+
19
+ if __name__ == "__main__":
20
+ gradio_app.launch(debug=True)
lm-evaluation-harness ADDED
@@ -0,0 +1 @@
 
 
1
+ Subproject commit 49695e8d94c3ab011b7ae8814d809de30b1b1182