kevineen commited on
Commit
1d997c9
1 Parent(s): 73946b5
Files changed (1) hide show
  1. run.py +34 -38
run.py CHANGED
@@ -4,6 +4,7 @@ from datasets import load_dataset
4
  from type.dataset_type import TanukiPhase2AnnotationDataset
5
 
6
  js = """
 
7
  function blockEnter(event) {
8
  document.addEventListener('DOMContentLoaded', (event) => {
9
  const textbox = document.getElementById('answer');
@@ -17,8 +18,6 @@ function blockEnter(event) {
17
  """
18
 
19
  target_dataset = TanukiPhase2AnnotationDataset()
20
- initial_answer_text = ""
21
- initial_answer_text_2 = ""
22
 
23
  dataset_list = [
24
  "hatakeyama-llm-team/WikiBookJa",
@@ -30,52 +29,47 @@ dataset_list = [
30
  "kanhatakeyama/AutoMultiTurnByMixtral8x22b",
31
  "kanhatakeyama/LogicalDatasetsByMixtral8x22b"]
32
 
 
 
 
 
 
 
 
33
  def load_css():
34
  with open("style.css", "r") as file:
35
  css_content = file.read()
36
  return css_content
37
 
38
- def set_name(profile: gr.OAuthProfile | None) -> str:
39
  if profile is None:
40
  return "プライベートデータセット取得のためにログインしてください。"
41
  return f'{profile.username}さん、よろしくお願いいたします。'
42
 
43
-
44
- def list_private_models(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None) -> str:
45
- if oauth_token is None:
46
- return "プライベートデータセット取得のためにログインしてください。"
47
- models = [
48
- f"{model.id} ({'private' if model.private else 'public'})"
49
- for model in list_models(author=profile.username, token=oauth_token.token)
50
- ]
51
- return "選択中のデータセット:\n\n" + "\n - ".join(models)
52
-
53
-
54
- def toggle_buttons(profile: gr.OAuthProfile | None):
55
- if profile is None:
56
- return gr.update(visible=True), gr.update(visible=False)
57
- return gr.update(visible=False), gr.update(visible=True)
58
-
59
-
60
- def load_data(choice_dataset, profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None) -> str:
61
  if oauth_token is None:
62
  return "ログインしてからデータセットを表示してください。"
63
- dataset = load_dataset(choice_dataset)
64
- return dataset
 
 
 
65
 
66
 
67
  def display_dataset(choice_dataset, profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None):
68
  if profile is None:
69
  return gr.update(visible=True, value="ログインしてデータセットを表示してください。"), None, None
70
- dataset = load_data(choice_dataset, profile, oauth_token)
71
- if dataset:
72
  # "train" スプリットの最初のデータを取得
73
- first_data = dataset['train'][0]
74
- question = first_data.get("question", "No question found")
75
- answer = first_data.get("answer", "No answer found")
 
76
 
77
  # 初期値を設定しておく
78
  initial_answer_text = answer
 
79
  return gr.update(visible=False), gr.update(value=question, interactive=False), gr.update(value=answer)
80
  else:
81
  return gr.update(visible=True, value="データセットのロードに失敗しました。"), None, None
@@ -101,17 +95,14 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
101
 
102
  with gr.Row(equal_height=True):
103
 
104
- login_btn = gr.LoginButton(visible=True, scale=1)
105
- logout_btn = gr.LogoutButton(visible=False, scale=1)
106
 
107
- profile = gr.Markdown()
108
- theme_button = gr.Button("Switch Theme")
109
 
 
110
  theme_button.click(fn=update_theme, outputs=None)
111
 
112
- demo.load(set_name, inputs=None, outputs=profile)
113
- demo.load(toggle_buttons, inputs=None, outputs=[login_btn, logout_btn])
114
-
115
 
116
  def choice_dataset_fn(choice_dataset):
117
  return f"{choice_dataset}"
@@ -120,13 +111,18 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
120
 
121
  choice_dataset = gr.Dropdown(label="アノテーションするデータセット",
122
  choices=dataset_list,
123
- value="a", elem_id="dataset_sel")
 
124
 
125
  data_load_btn = gr.Button("データセットを読み込む")
126
 
 
 
 
127
  choice_dataset.change(choice_dataset_fn, inputs=[choice_dataset])
128
 
129
  dataset_display = gr.Markdown(visible=False)
 
130
  question_text = gr.Textbox(label="質問: ", interactive=False)
131
 
132
  with gr.Row(equal_height=True):
@@ -144,9 +140,9 @@ with gr.Blocks(theme=theme_, css=load_css()) as demo:
144
  def on_submit(answer_text):
145
  return f" {answer_text}"
146
 
147
- with gr.Tab("アノテ済みデータセット"):
148
 
149
- gr.Textbox("データセットID", lines=1, placeholder="データセットIDを入力してください。")
150
 
151
  if __name__ == "__main__":
152
  demo.launch()
 
4
  from type.dataset_type import TanukiPhase2AnnotationDataset
5
 
6
  js = """
7
+ # テキストボックスでEnterキーを無効化する
8
  function blockEnter(event) {
9
  document.addEventListener('DOMContentLoaded', (event) => {
10
  const textbox = document.getElementById('answer');
 
18
  """
19
 
20
  target_dataset = TanukiPhase2AnnotationDataset()
 
 
21
 
22
  dataset_list = [
23
  "hatakeyama-llm-team/WikiBookJa",
 
29
  "kanhatakeyama/AutoMultiTurnByMixtral8x22b",
30
  "kanhatakeyama/LogicalDatasetsByMixtral8x22b"]
31
 
32
+ # データセットと現在のデータのインデックスを保持する状態変数
33
+ drop_sel_dataset = gr.State(None)
34
+ current_dataset = gr.State(None)
35
+ current_index = gr.State(0)
36
+ initial_answer_text = gr.State("")
37
+ initial_answer_text_2 = gr.State("")
38
+
39
  def load_css():
40
  with open("style.css", "r") as file:
41
  css_content = file.read()
42
  return css_content
43
 
44
+ def hello(profile: gr.OAuthProfile | None) -> str:
45
  if profile is None:
46
  return "プライベートデータセット取得のためにログインしてください。"
47
  return f'{profile.username}さん、よろしくお願いいたします。'
48
 
49
+ def load_data(choice_dataset, oauth_token: gr.OAuthToken | None) -> str:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  if oauth_token is None:
51
  return "ログインしてからデータセットを表示してください。"
52
+ try:
53
+ drop_sel_dataset = load_dataset(choice_dataset)
54
+ return drop_sel_dataset
55
+ except Exception as e:
56
+ return None
57
 
58
 
59
  def display_dataset(choice_dataset, profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None):
60
  if profile is None:
61
  return gr.update(visible=True, value="ログインしてデータセットを表示してください。"), None, None
62
+ first_data = load_data(choice_dataset, oauth_token)
63
+ if first_data:
64
  # "train" スプリットの最初のデータを取得
65
+ current_dataset = first_data['train'][0]
66
+ current_index = 0
67
+ question = current_dataset.get("question", "No question found")
68
+ answer = current_dataset.get("answer", "No answer found")
69
 
70
  # 初期値を設定しておく
71
  initial_answer_text = answer
72
+
73
  return gr.update(visible=False), gr.update(value=question, interactive=False), gr.update(value=answer)
74
  else:
75
  return gr.update(visible=True, value="データセットのロードに失敗しました。"), None, None
 
95
 
96
  with gr.Row(equal_height=True):
97
 
98
+ gr.LoginButton(value="ログイン",logout_value="ログアウト", scale=1)
 
99
 
100
+ profile_name = gr.Markdown()
 
101
 
102
+ theme_button = gr.Button("Switch Theme")
103
  theme_button.click(fn=update_theme, outputs=None)
104
 
105
+ demo.load(hello, inputs=None, outputs=profile_name)
 
 
106
 
107
  def choice_dataset_fn(choice_dataset):
108
  return f"{choice_dataset}"
 
111
 
112
  choice_dataset = gr.Dropdown(label="アノテーションするデータセット",
113
  choices=dataset_list,
114
+ value="hatakeyama-llm-team/AutoGeneratedJapaneseQA",
115
+ elem_id="dataset_sel")
116
 
117
  data_load_btn = gr.Button("データセットを読み込む")
118
 
119
+ # データセットのロードメッセージ表示
120
+ dataset_load_message = gr.Markdown(visible=False)
121
+
122
  choice_dataset.change(choice_dataset_fn, inputs=[choice_dataset])
123
 
124
  dataset_display = gr.Markdown(visible=False)
125
+
126
  question_text = gr.Textbox(label="質問: ", interactive=False)
127
 
128
  with gr.Row(equal_height=True):
 
140
  def on_submit(answer_text):
141
  return f" {answer_text}"
142
 
143
+ # with gr.Tab("アノテ済みデータセット"):
144
 
145
+ # gr.Textbox("データセットID", lines=1, placeholder="データセットIDを入力してください。")
146
 
147
  if __name__ == "__main__":
148
  demo.launch()