Siyunb323 commited on
Commit
49b4797
·
1 Parent(s): c0035d4

Test application

Browse files
Files changed (1) hide show
  1. app.py +94 -4
app.py CHANGED
@@ -1,7 +1,97 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
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():
53
+ with gr.Column():
54
+ task_dropdown = gr.Dropdown(
55
+ label="Task Name",
56
+ choices=["Creativity", "Appropriateness"],
57
+ value="Creativity"
58
+ )
59
+ model_dropdown = gr.Dropdown(
60
+ label="Model Name",
61
+ choices=[
62
+ "One-phase Fine-tuned BERT",
63
+ "Two-phase Fine-tuned BERT"],
64
+ value="Two-phase Fine-tuned BERT"
65
+ )
66
+ pooling_dropdown = gr.Dropdown(
67
+ label="Pooling",
68
+ choices=["mean", "cls"],
69
+ value="cls"
70
+ )
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()
97