Spaces:
Build error
Build error
merge
Browse files- app.py +47 -0
- gradio_samples/bertviz/app.py +24 -24
app.py
CHANGED
|
@@ -10,12 +10,41 @@ import matplotlib.pyplot as plt
|
|
| 10 |
import numpy as np
|
| 11 |
from datetime import datetime
|
| 12 |
import scipy
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
# os.system('git clone https://github.com/EleutherAI/lm-evaluation-harness')
|
| 14 |
# os.system('cd lm-evaluation-harness')
|
| 15 |
# os.system('pip install -e .')
|
| 16 |
# -i https://pypi.tuna.tsinghua.edu.cn/simple
|
| 17 |
# 第一个功能:基于输入文本和对应的损失值对文本进行着色展示
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
def color_text(text_list=["hi", "FreshEval","!"], loss_list=[0.1,0.7]):
|
| 20 |
"""
|
| 21 |
根据损失值为文本着色。
|
|
@@ -454,6 +483,24 @@ with gr.Blocks() as demo:
|
|
| 454 |
see the questions
|
| 455 |
'''
|
| 456 |
|
|
|
|
| 457 |
|
| 458 |
demo.launch(debug=True)
|
| 459 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
import numpy as np
|
| 11 |
from datetime import datetime
|
| 12 |
import scipy
|
| 13 |
+
<<<<<<< HEAD
|
| 14 |
+
=======
|
| 15 |
+
import shutil
|
| 16 |
+
>>>>>>> 95f252d5216b18bcd503dc7425ceb1dd1ccb8f6b
|
| 17 |
# os.system('git clone https://github.com/EleutherAI/lm-evaluation-harness')
|
| 18 |
# os.system('cd lm-evaluation-harness')
|
| 19 |
# os.system('pip install -e .')
|
| 20 |
# -i https://pypi.tuna.tsinghua.edu.cn/simple
|
| 21 |
# 第一个功能:基于输入文本和对应的损失值对文本进行着色展示
|
| 22 |
|
| 23 |
+
|
| 24 |
+
csv_file_path = 'data.csv'
|
| 25 |
+
|
| 26 |
+
def save_and_share_csv():
|
| 27 |
+
src_path = './data/0309_merge_gjo.csv'
|
| 28 |
+
dest_dir = './save/'
|
| 29 |
+
if not os.path.exists(dest_dir):
|
| 30 |
+
os.makedirs(dest_dir)
|
| 31 |
+
dest_path = os.path.join(dest_dir, '0309_merge_gjo_shared.csv')
|
| 32 |
+
shutil.copy(src_path, dest_path)
|
| 33 |
+
return """
|
| 34 |
+
<script>
|
| 35 |
+
alert('Data shared successfully! CSV saved to ./save/ directory.');
|
| 36 |
+
</script>
|
| 37 |
+
"""
|
| 38 |
+
#弹窗没有但反正能保存
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def plot_ppl():
|
| 42 |
+
df = pd.read_csv(csv_file_path)
|
| 43 |
+
# 假设df已经有适当的列用于绘图
|
| 44 |
+
fig = px.line(df, x='date', y='loss_mean_at_1000', color='model', title='PPL with Time')
|
| 45 |
+
return fig
|
| 46 |
+
|
| 47 |
+
|
| 48 |
def color_text(text_list=["hi", "FreshEval","!"], loss_list=[0.1,0.7]):
|
| 49 |
"""
|
| 50 |
根据损失值为文本着色。
|
|
|
|
| 483 |
see the questions
|
| 484 |
'''
|
| 485 |
|
| 486 |
+
<<<<<<< HEAD
|
| 487 |
|
| 488 |
demo.launch(debug=True)
|
| 489 |
|
| 490 |
+
=======
|
| 491 |
+
with gr.Row():
|
| 492 |
+
plot_btn = gr.Button("Generate Plot")
|
| 493 |
+
share_btn = gr.Button("Share Data")
|
| 494 |
+
with gr.Row():
|
| 495 |
+
plot_space = gr.Plot()
|
| 496 |
+
share_result = gr.Textbox(visible=False)
|
| 497 |
+
|
| 498 |
+
# 当点击“Generate Plot”按钮时,调用plotly_plot_question函数并在plot_space显示结果
|
| 499 |
+
plot_btn.click(fn=plotly_plot_question, inputs=[], outputs=plot_space)
|
| 500 |
+
|
| 501 |
+
# 当点击“Share Data”按钮时,调用save_and_share_csv函数并在share_result显示结果
|
| 502 |
+
share_btn.click(fn=save_and_share_csv, inputs=[], outputs=share_result)
|
| 503 |
+
|
| 504 |
+
|
| 505 |
+
demo.launch(share=True,debug=True)
|
| 506 |
+
>>>>>>> 95f252d5216b18bcd503dc7425ceb1dd1ccb8f6b
|
gradio_samples/bertviz/app.py
CHANGED
|
@@ -15,7 +15,7 @@ from tqdm.notebook import tqdm
|
|
| 15 |
from torch.utils.data import DataLoader
|
| 16 |
from functools import partial
|
| 17 |
|
| 18 |
-
from transformers import AutoTokenizer,
|
| 19 |
|
| 20 |
from bertviz import model_view, head_view
|
| 21 |
from bertviz_gradio import head_view_mod
|
|
@@ -23,44 +23,44 @@ from bertviz_gradio import head_view_mod
|
|
| 23 |
|
| 24 |
|
| 25 |
model_es = "Helsinki-NLP/opus-mt-en-es"
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
tokenizer_es = AutoTokenizer.from_pretrained(model_es)
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
|
| 35 |
-
model_tr_es =
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
|
| 40 |
model_es = inseq.load_model("Helsinki-NLP/opus-mt-en-es", "input_x_gradient")
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
|
| 45 |
dict_models = {
|
| 46 |
'en-es': model_es,
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
}
|
| 51 |
|
| 52 |
dict_models_tr = {
|
| 53 |
'en-es': model_tr_es,
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
}
|
| 58 |
|
| 59 |
dict_tokenizer_tr = {
|
| 60 |
'en-es': tokenizer_es,
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
}
|
| 65 |
|
| 66 |
saliency_examples = [
|
|
@@ -196,4 +196,4 @@ with gr.Blocks(js="plotsjs_bertviz.js") as demo:
|
|
| 196 |
# demo.load(None,None,None,js="plotsjs.js")
|
| 197 |
|
| 198 |
if __name__ == "__main__":
|
| 199 |
-
demo.launch()
|
|
|
|
| 15 |
from torch.utils.data import DataLoader
|
| 16 |
from functools import partial
|
| 17 |
|
| 18 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, AutoModelForSeq2SeqLM
|
| 19 |
|
| 20 |
from bertviz import model_view, head_view
|
| 21 |
from bertviz_gradio import head_view_mod
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
model_es = "Helsinki-NLP/opus-mt-en-es"
|
| 26 |
+
model_fr = "Helsinki-NLP/opus-mt-en-fr"
|
| 27 |
+
model_zh = "Helsinki-NLP/opus-mt-en-zh"
|
| 28 |
+
model_sw = "Helsinki-NLP/opus-mt-en-sw"
|
| 29 |
|
| 30 |
tokenizer_es = AutoTokenizer.from_pretrained(model_es)
|
| 31 |
+
tokenizer_fr = AutoTokenizer.from_pretrained(model_fr)
|
| 32 |
+
tokenizer_zh = AutoTokenizer.from_pretrained(model_zh)
|
| 33 |
+
tokenizer_sw = AutoTokenizer.from_pretrained(model_sw)
|
| 34 |
|
| 35 |
+
model_tr_es =AutoModelForSeq2SeqLM.from_pretrained(model_es)
|
| 36 |
+
model_tr_fr = AutoModelForSeq2SeqLM.from_pretrained(model_fr)
|
| 37 |
+
model_tr_zh =AutoModelForSeq2SeqLM.from_pretrained(model_zh)
|
| 38 |
+
model_tr_sw = AutoModelForSeq2SeqLM.from_pretrained(model_sw)
|
| 39 |
|
| 40 |
model_es = inseq.load_model("Helsinki-NLP/opus-mt-en-es", "input_x_gradient")
|
| 41 |
+
model_fr = inseq.load_model("Helsinki-NLP/opus-mt-en-fr", "input_x_gradient")
|
| 42 |
+
model_zh = inseq.load_model("Helsinki-NLP/opus-mt-en-zh", "input_x_gradient")
|
| 43 |
+
model_sw = inseq.load_model("Helsinki-NLP/opus-mt-en-sw", "input_x_gradient")
|
| 44 |
|
| 45 |
dict_models = {
|
| 46 |
'en-es': model_es,
|
| 47 |
+
'en-fr': model_fr,
|
| 48 |
+
'en-zh': model_zh,
|
| 49 |
+
'en-sw': model_sw,
|
| 50 |
}
|
| 51 |
|
| 52 |
dict_models_tr = {
|
| 53 |
'en-es': model_tr_es,
|
| 54 |
+
'en-fr': model_tr_fr,
|
| 55 |
+
'en-zh': model_tr_zh,
|
| 56 |
+
'en-sw': model_tr_sw,
|
| 57 |
}
|
| 58 |
|
| 59 |
dict_tokenizer_tr = {
|
| 60 |
'en-es': tokenizer_es,
|
| 61 |
+
'en-fr': tokenizer_fr,
|
| 62 |
+
'en-zh': tokenizer_zh,
|
| 63 |
+
'en-sw': tokenizer_sw,
|
| 64 |
}
|
| 65 |
|
| 66 |
saliency_examples = [
|
|
|
|
| 196 |
# demo.load(None,None,None,js="plotsjs.js")
|
| 197 |
|
| 198 |
if __name__ == "__main__":
|
| 199 |
+
demo.launch(share=True)
|