import streamlit as st import openai import os import outlines # =============== 基本設定 =============== #openai.api_key = st.secrets["OPENAI_API_KEY"] # 建議放在 .streamlit/secrets.toml 中 def choose_cleint(model_id): api_key = '' client = None if( 'o3-' in model_id or 'gpt-' in model_id): api_key = os.environ["CHATGPT_API_KEY"] client = openai.OpenAI(api_key=api_key) else: api_key = os.environ["TOGETHER_API_KEY"] client = openai.OpenAI(api_key=api_key,base_url="https://api.together.xyz/v1") info = f'api_key:{api_key}, model_id:{model_id}' st.text_area("info: ", info) return client # =============== 呼叫 LLM 摘要函數 =============== def call_llm(model_id, content): client = choose_cleint(model_id) #client = openai.OpenAI(api_key=api_key,base_url="https://api.together.xyz/v1") response = client.chat.completions.create( model = model_id, messages=[{"role": "user", "content": content}],) return response.choices[0].message.content ''' response = client.chat.completions.create( model = model_id, messages=[{"role": "user", "content": prompt}],)''' return response['choices'][0]['message']['content'] def file_name(selected_eval_model): if(len(selected_eval_model.split('/')) > 1): return selected_eval_model.split('/')[1] else: return selected_eval_model # =============== Streamlit 介面 =============== st.title("📑 會議紀錄摘要與評估系統") # 1️⃣ 上傳會議紀錄文字檔 uploaded_file = st.file_uploader("請上傳會議紀錄文字檔 (.txt)", type="txt") # 2️⃣ 選擇摘要用的 LLM 模型 llm_models = [ "Qwen/Qwen2.5-Coder-32B-Instruct", "Qwen/Qwen2-VL-72B-Instruct", "deepseek-ai/DeepSeek-R1-Distill-Qwen-14B", "gpt-4o", "o3-mini", "gpt-3.5-turbo" ] # 3️⃣ 按鈕 → 產生摘要 if uploaded_file : selected_summary_model = st.selectbox("選擇用來摘要的 LLM 模型", llm_models) if(selected_summary_model and st.button("🚀 產生會議摘要")): meeting_text = uploaded_file.read().decode("utf-8") if(meeting_text): #summary_task = "請將以下會議紀錄內容進行摘要,並以條列式清楚表達重點:" prompt_summary = f''' You are a helpful assistant specialized in summarizing business meeting transcripts. Given a detailed company meeting transcript, your task is to generate a well-structured summary that includes the following: (1)Meeting Outline A high-level bullet-point outline of the meeting topics discussed, in the order they appeared. (2)Speaker Contributions A section listing each participant’s key opinions, statements, and concerns raised during the meeting. (3)Key Conclusions and Action Items A clear list of the main conclusions reached by the team and the action plans assigned to each person or department. The summary should be concise, clear, and organized, avoiding unnecessary repetition while preserving essential details. Your summary should be written in traditional Chinese. ==== Following is the meeting transcripts: {meeting_text} ''' #cprint(prompt,"yellow") summary_result = call_llm(selected_summary_model, meeting_text) # 存檔 summary_filename = f"summary_{file_name(selected_summary_model)}.txt" with open(summary_filename, "w", encoding="utf-8") as f: f.write(summary_result) st.success(f"✅ 已完成摘要,檔名:{summary_filename}") st.text_area("📋 產生的會議摘要", summary_result, height=300) # 保留原文與摘要供評估用 st.session_state['meeting_text'] = meeting_text st.session_state['summary_result'] = summary_result # 4️⃣ 選擇評價用的 LLM 模型 if 'summary_result' in st.session_state: selected_eval_model = st.selectbox("選擇用來評價的 LLM 模型", llm_models) # 5️⃣ 按鈕 → 產生評價 if selected_eval_model and st.button("📝 產生摘要評價"): #eval_task = "請根據提供的會議紀錄原文與產生的摘要,評估該摘要的完整性、準確性、表達清晰度,並給予建議。" #combined_content = f"【會議紀錄原文】\n{st.session_state['meeting_text']}\n\n【會議摘要】\n{st.session_state['summary_result']}" prompt_evaluation = f''' You are a professional meeting summary reviewer. Please evaluate the following meeting summary based on these three criteria: 1. Coverage Completeness: Does the summary cover all the key points discussed in the meeting? 2. Accuracy: Is the summary faithful to the original meeting content, without adding, omitting, or distorting information? 3. Clarity and Conciseness: Is the summary clear, well-structured, and avoids unnecessary repetition or irrelevant content? Provide a score from 1 to 5 for each item. Then, calculate a total score (maximum 15 points). Finally, write a brief comment about the overall quality. ==== 【會議原文】 {st.session_state['meeting_text']} 【會議摘要】 {st.session_state['summary_result']} ==== Please reply in the following format in Traditional Chinese: 完整性:X/5 準確性:X/5 簡潔性:X/5 總分:X/15 評語:XXXXX ''' evaluation_result = call_llm(selected_eval_model, prompt_evaluation) eval_filename = "" # 存檔 eval_filename = f"evaluation_{file_name(selected_eval_model)}.txt" with open(eval_filename, "w", encoding="utf-8") as f: f.write(evaluation_result) st.success(f"✅ 已完成評價,檔名:{eval_filename}") st.text_area("📖 評估結果", evaluation_result, height=300)