Siyunb323 commited on
Commit
f57196e
·
1 Parent(s): a87b509

Test application

Browse files
Files changed (1) hide show
  1. app.py +30 -43
app.py CHANGED
@@ -1,52 +1,31 @@
1
  import gradio as gr
2
  import pandas as pd
3
 
 
 
 
 
 
 
4
  # 定义处理函数
5
  def process_data(task_name, model_name, pooling_method, input_text, file=None):
6
- # 模拟数据处理逻辑
7
  if file:
8
  df = pd.read_csv(file.name)
9
  output = f"Processed {len(df)} rows from uploaded file using task: {task_name}, model: {model_name}, pooling: {pooling_method}."
10
- dataframe_output = df.head().to_html() # 显示前几行数据
 
11
  else:
12
  lines = input_text.split("\n")
13
  output = f"Processed {len(lines)} rows of text using task: {task_name}, model: {model_name}, pooling: {pooling_method}."
14
- dataframe_output = "<p>No file uploaded. DataFrame preview unavailable.</p>"
 
15
 
16
- return output, dataframe_output, "File processing completed."
17
 
18
  # 使用Blocks定义布局
19
- with gr.Blocks() as interface:
20
- gr.Markdown("# TransDis-CreativityAutoAssessment")
21
- gr.Markdown(
22
- "Two-Phase Fine-tuned BERTは、bert-base-japaneseモデルに基づいた自動評価システムで、日本語の多用途タスク(AUT)における創造性と適切性を評価するために使用されます(論文はこちら:https://link.springer.com/article/xx.xxxx/sxxxxx-xxx-xxxx-x)。"
23
- "プロンプトと回答のデータを入力してください。データは1行ごとに用途を記述し、カンマで区切ってください。"
24
- "データは、デモのようにテキストボックスに直接入力するか、カンマ区切りのCSV形式ファイルまたはxlsx形式ファイルをアップロードすることで入力できます。"
25
- "評価に使用するモデルは、Two-Phase Fine-tuned BERT の他に One-phase BERT もあり、いずれも日本語にのみ対応しています。"
26
- "Two-phase BERTは、低い現実性の回答に対して創造性評価を最適化しており、適切性と創造性の両方を評価できます。"
27
- "一方、One-phase BERTは、AUT回答の創造性のみを評価します。"
28
- "Pooling方法としてcls-poolingを使用することをお勧めします。"
29
- "エラーが発生した場合は、データを簡略化し、行数を減らして試してください。"
30
- "それでも解決しない場合は、入力形式が誤っている可能性があるため、CSVとして保存し直してアップロードをお試しください。"
31
- "このシステムはHuggingFaceが提供する無料サーバーを使用しており、計算にはCPUのみを使用するため、処理速度が遅い場合があります。"
32
- "このスペースをあなたのアカウントにコピー(推奨)し、ハードウェアをアップグレードすることで処理速度を向上させることが可能です。"
33
- "その他のサポートやバグ報告については、[email protected]までご連絡ください。"
34
- "\n\n"
35
- "Two-Phase Fine-tuned BERT is an automatic evaluation system based on the bert-base-japanese model, designed to evaluate creativity and appropriateness in Japanese alternative uses task (AUT) (see the paper at https://link.springer.com/article/xx.xxxx/sxxxxx-xxx-xxxx-x)."
36
- "Enter the data consisting of prompts and responses, with one usage per line, separated by commas."
37
- "You can input the data directly into the text box as shown in the demos, or upload a comma-separated CSV file or an xlsx file as input."
38
- "The models available for evaluation also include One-phase Fine-tuned BERT except for Two-phase Fine-tuned BERT, both of which are applicable only to Japanese."
39
- "Two-phase BERT is optimized for creativity scoring for responses with low practicality and can evaluate both appropriateness and creativity."
40
- "On the other hand, One-phase BERT is designed solely for evaluating creativity in AUT responses."
41
- "We recommend using cls-pooling as the pooling method."
42
- " If an error occurs, try simplifying your data by reducing the number of rows."
43
- "If this doesn’t resolve the issue, the input format may be incorrect. Please try saving the data again as a comma-separated CSV file before uploading it."
44
- "This system uses the free servers provided by HuggingFace, which only support CPU processing, so it may run slowly."
45
- "You can copy this space to your account (recommended) and choose upgraded hardware to improve processing speed."
46
- "For further assistance or to report bugs, please contact [email protected]."
47
- "\n\n"
48
- "Reference: Wang, S., ..., (2025). Enhancing Creativity Evaluation in Divergent Thinking: A Two-phase Fine-tuned BERT Incorporating Appropriateness Supervision. https://doi.org/xx.xxxx/sxxxxx-xxx-xxxxx-x"
49
- )
50
 
51
  # 固定布局:分成三列
52
  with gr.Row():
@@ -71,26 +50,34 @@ with gr.Blocks() as interface:
71
  text_input = gr.Textbox(
72
  label="Text Input",
73
  lines=10,
74
- placeholder="Enter text data here..."
75
  )
76
  file_input = gr.File(
77
  label="Input File",
78
  type="filepath",
79
  file_types=[".csv", ".xlsx"]
80
  )
 
 
 
 
 
81
  with gr.Column():
82
- output_box = gr.Textbox(label="Output", lines=5, interactive=False)
83
- dataframe_output = gr.HTML(label="DataFrame Preview")
84
- file_output = gr.Textbox(label="Output File Status", interactive=False)
85
-
86
- # 添加按钮并链接处理函数
87
- submit_button = gr.Button("Submit")
88
  submit_button.click(
89
  process_data,
90
  inputs=[task_dropdown, model_dropdown, pooling_dropdown, text_input, file_input],
91
  outputs=[output_box, dataframe_output, file_output]
92
  )
93
-
 
 
 
 
94
 
95
  # 启动界面
96
  interface.launch()
 
1
  import gradio as gr
2
  import pandas as pd
3
 
4
+ with open("./description.md", "r", encoding="utf-8") as file:
5
+ description_text = file.read()
6
+
7
+ with open("./placeholder_demo.txt", "r", encoding="utf-8") as file:
8
+ placeholder_demo = file.read()
9
+
10
  # 定义处理函数
11
  def process_data(task_name, model_name, pooling_method, input_text, file=None):
 
12
  if file:
13
  df = pd.read_csv(file.name)
14
  output = f"Processed {len(df)} rows from uploaded file using task: {task_name}, model: {model_name}, pooling: {pooling_method}."
15
+ dataframe_output = df # 返回数据框用于显示
16
+ file_output = df # 输出文件框显示相同的数据
17
  else:
18
  lines = input_text.split("\n")
19
  output = f"Processed {len(lines)} rows of text using task: {task_name}, model: {model_name}, pooling: {pooling_method}."
20
+ dataframe_output = pd.DataFrame({"Error": ["No file uploaded. DataFrame preview unavailable."]}) # 错误信息
21
+ file_output = pd.DataFrame()
22
 
23
+ return output, dataframe_output, file_output
24
 
25
  # 使用Blocks定义布局
26
+ with gr.Blocks(css="./custom_styles.css") as interface:
27
+ gr.Markdown("<h1 style='text-align: center;'>TwoPhaseBERT-CreativityAutoAssessmen</h1>")
28
+ gr.Markdown(description_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  # 固定布局:分成三列
31
  with gr.Row():
 
50
  text_input = gr.Textbox(
51
  label="Text Input",
52
  lines=10,
53
+ placeholder=placeholder_demo
54
  )
55
  file_input = gr.File(
56
  label="Input File",
57
  type="filepath",
58
  file_types=[".csv", ".xlsx"]
59
  )
60
+ # 按钮部分
61
+ with gr.Row():
62
+ clear_button = gr.Button("Clear", elem_classes="custom-clear")
63
+ submit_button = gr.Button("Submit", elem_classes="custom-submit")
64
+
65
  with gr.Column():
66
+ output_box = gr.Textbox(label="Warning", lines=5, interactive=False)
67
+ dataframe_output = gr.Dataframe(label="DataFrame", interactive=False)
68
+ file_output = gr.File(label="Output File", interactive=False)
69
+
70
+ # 按钮功能链接
 
71
  submit_button.click(
72
  process_data,
73
  inputs=[task_dropdown, model_dropdown, pooling_dropdown, text_input, file_input],
74
  outputs=[output_box, dataframe_output, file_output]
75
  )
76
+ clear_button.click(
77
+ lambda: ("", pd.DataFrame(), None),
78
+ inputs=[],
79
+ outputs=[output_box, dataframe_output, file_output]
80
+ )
81
 
82
  # 启动界面
83
  interface.launch()