Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 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()
|
|
|