Nuo Chen commited on
Commit
6076324
1 Parent(s): 34dbc36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -1
app.py CHANGED
@@ -10,12 +10,38 @@ 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 +480,18 @@ 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
+ import shutil
14
  # os.system('git clone https://github.com/EleutherAI/lm-evaluation-harness')
15
  # os.system('cd lm-evaluation-harness')
16
  # os.system('pip install -e .')
17
  # -i https://pypi.tuna.tsinghua.edu.cn/simple
18
  # 第一个功能:基于输入文本和对应的损失值对文本进行着色展示
19
 
20
+
21
+ csv_file_path = 'data.csv'
22
+
23
+ def save_and_share_csv():
24
+ src_path = './data/0309_merge_gjo.csv'
25
+ dest_dir = './save/'
26
+ if not os.path.exists(dest_dir):
27
+ os.makedirs(dest_dir)
28
+ dest_path = os.path.join(dest_dir, '0309_merge_gjo_shared.csv')
29
+ shutil.copy(src_path, dest_path)
30
+ return """
31
+ <script>
32
+ alert('Data shared successfully! CSV saved to ./save/ directory.');
33
+ </script>
34
+ """
35
+ #弹窗没有但反正能保存
36
+
37
+
38
+ def plot_ppl():
39
+ df = pd.read_csv(csv_file_path)
40
+ # 假设df已经有适当的列用于绘图
41
+ fig = px.line(df, x='date', y='loss_mean_at_1000', color='model', title='PPL with Time')
42
+ return fig
43
+
44
+
45
  def color_text(text_list=["hi", "FreshEval","!"], loss_list=[0.1,0.7]):
46
  """
47
  根据损失值为文本着色。
 
480
  see the questions
481
  '''
482
 
483
+ with gr.Row():
484
+ plot_btn = gr.Button("Generate Plot")
485
+ share_btn = gr.Button("Share Data")
486
+ with gr.Row():
487
+ plot_space = gr.Plot()
488
+ share_result = gr.Textbox(visible=False)
489
+
490
+ # 当点击“Generate Plot”按钮时,调用plotly_plot_question函数并在plot_space显示结果
491
+ plot_btn.click(fn=plotly_plot_question, inputs=[], outputs=plot_space)
492
+
493
+ # 当点击“Share Data”按钮时,调用save_and_share_csv函数并在share_result显示结果
494
+ share_btn.click(fn=save_and_share_csv, inputs=[], outputs=share_result)
495
 
 
496
 
497
+ demo.launch(share=True,debug=True)