Spaces:
Sleeping
Sleeping
add: announcement
Browse files
app.py
CHANGED
@@ -57,6 +57,23 @@ def log_to_google_sheet(question, answer, contexts, scores):
|
|
57 |
except Exception as e:
|
58 |
print("寫入 Google Sheet 失敗:", str(e))
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
def validate_openai_key(api_key):
|
61 |
try:
|
62 |
client = OpenAI(api_key=api_key)
|
@@ -262,6 +279,7 @@ with gr.Blocks() as demo:
|
|
262 |
- 🔁 [分流 B](https://huggingface.co/spaces/KSLab/RAG_Evaluator_B)
|
263 |
- 🔁 [分流 C](https://huggingface.co/spaces/KSLab/RAG_Evaluator_C)
|
264 |
""")
|
|
|
265 |
|
266 |
file_input = gr.File(label="上傳 Evaluation_Dataset.csv")
|
267 |
api_key_input = gr.Textbox(label="OpenAI API Key", type="password")
|
|
|
57 |
except Exception as e:
|
58 |
print("寫入 Google Sheet 失敗:", str(e))
|
59 |
|
60 |
+
def fetch_announcement_from_sheet():
|
61 |
+
try:
|
62 |
+
url = os.environ.get("ANNOUNCEMENT_URL")
|
63 |
+
if not url:
|
64 |
+
return "📢 尚無公告"
|
65 |
+
df = pd.read_csv(url)
|
66 |
+
|
67 |
+
if "Announcement" in df.columns:
|
68 |
+
content = str(df["announcement"].iloc[0]).strip()
|
69 |
+
if not content:
|
70 |
+
return "📢 尚無公告"
|
71 |
+
return f"📢 {content}"
|
72 |
+
else:
|
73 |
+
return "📢 無法讀取公告欄位"
|
74 |
+
except Exception as e:
|
75 |
+
return f"📢 載入公告失敗:{str(e)}"
|
76 |
+
|
77 |
def validate_openai_key(api_key):
|
78 |
try:
|
79 |
client = OpenAI(api_key=api_key)
|
|
|
279 |
- 🔁 [分流 B](https://huggingface.co/spaces/KSLab/RAG_Evaluator_B)
|
280 |
- 🔁 [分流 C](https://huggingface.co/spaces/KSLab/RAG_Evaluator_C)
|
281 |
""")
|
282 |
+
gr.Markdown(fetch_announcement_from_sheet())
|
283 |
|
284 |
file_input = gr.File(label="上傳 Evaluation_Dataset.csv")
|
285 |
api_key_input = gr.Textbox(label="OpenAI API Key", type="password")
|