Browen0311 commited on
Commit
34ccda0
·
verified ·
1 Parent(s): b2e13b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -54
app.py CHANGED
@@ -1,11 +1,8 @@
1
  import os
2
- from dotenv import load_dotenv
3
  import gradio as gr
4
  from openai import OpenAI
5
- from datetime import datetime
6
 
7
- # 載入環境變數
8
- load_dotenv()
9
  client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
10
 
11
  def evaluate_essay(message, history, additional_prompt):
@@ -104,55 +101,51 @@ def evaluate_essay(message, history, additional_prompt):
104
 
105
  return history
106
 
107
- def create_interface():
108
- with gr.Blocks(title="國文作文自動評分系統") as iface:
109
- gr.Markdown("""
110
- # 國文作文自動評分系統
111
- ## 評分標準說明
112
- 本系統採用以下四個面向進行評分:
113
- - 題旨發揮 (40%)
114
- - 資料掌握 (20%)
115
- - 結構安排 (20%)
116
- - 字句運用 (20%)
117
-
118
- 評分採用三等九級制(A+、A、A-、B+、B、B-、C+、C、C-)
119
- """)
120
-
121
- with gr.Row():
122
- with gr.Column(scale=4):
123
- chatbot = gr.Chatbot(
124
- value=[],
125
- height=500,
126
- bubble_full_width=False,
127
- avatar_images=("user.png", "assistant.png"),
128
- show_copy_button=True,
129
- layout="bubble",
130
- render_markdown=True
131
- )
132
- msg = gr.Textbox(
133
- label="請輸入作文內容",
134
- placeholder="在此輸入作文...",
135
- lines=3
136
- )
137
- additional_prompt = gr.Textbox(
138
- label="額外評分提示(選填)",
139
- placeholder="可輸入額外的評分要求或提示...",
140
- lines=2
141
- )
142
-
143
- with gr.Row():
144
- submit = gr.Button("開始評分", variant="primary")
145
- clear = gr.Button("清除對話")
146
-
147
- submit.click(
148
- evaluate_essay,
149
- inputs=[msg, chatbot, additional_prompt],
150
- outputs=chatbot
151
- )
152
- clear.click(lambda: [], outputs=chatbot)
153
 
154
- return iface
 
 
 
 
 
155
 
156
- if __name__ == "__main__":
157
- demo = create_interface()
158
- demo.launch(share=True)
 
1
  import os
 
2
  import gradio as gr
3
  from openai import OpenAI
 
4
 
5
+ # 直接從環境變數獲取 API key
 
6
  client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
7
 
8
  def evaluate_essay(message, history, additional_prompt):
 
101
 
102
  return history
103
 
104
+ # 建立 Gradio 介面
105
+ with gr.Blocks(title="國文作文自動評分系統") as demo:
106
+ gr.Markdown("""
107
+ # 國文作文自動評分系統
108
+ ## 評分標準說明
109
+ 本系統採用以下四個面向進行評分:
110
+ - 題旨發揮 (40%)
111
+ - 資料掌握 (20%)
112
+ - 結構安排 (20%)
113
+ - 字句運用 (20%)
114
+
115
+ 評分採用三等九級制(A+、A、A-、B+、B、B-、C+、C、C-)
116
+ """)
117
+
118
+ with gr.Row():
119
+ with gr.Column(scale=4):
120
+ chatbot = gr.Chatbot(
121
+ value=[],
122
+ height=500,
123
+ bubble_full_width=False,
124
+ show_copy_button=True,
125
+ layout="bubble",
126
+ render_markdown=True
127
+ )
128
+ msg = gr.Textbox(
129
+ label="請輸入作文內容",
130
+ placeholder="在此輸入作文...",
131
+ lines=3
132
+ )
133
+ additional_prompt = gr.Textbox(
134
+ label="額外評分提示(選填)",
135
+ placeholder="可輸入額外的評分要求或提示...",
136
+ lines=2
137
+ )
138
+
139
+ with gr.Row():
140
+ submit = gr.Button("開始評分", variant="primary")
141
+ clear = gr.Button("清除對話")
 
 
 
 
 
 
 
 
142
 
143
+ submit.click(
144
+ evaluate_essay,
145
+ inputs=[msg, chatbot, additional_prompt],
146
+ outputs=chatbot
147
+ )
148
+ clear.click(lambda: [], outputs=chatbot)
149
 
150
+ # 啟動應用
151
+ demo.launch()