Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| from smolagents import LiteLLMModel | |
| import os | |
| def load_model(): | |
| MODEL_NAMES = [ | |
| "Qwen/QwQ-32B", # 免費使用 | |
| ] | |
| model = LiteLLMModel( | |
| "together_ai" + "/" + MODEL_NAMES[0], | |
| temperature=0.2, | |
| api_key=os.getenv("TOGETHER_API_KEY") | |
| ) | |
| return model | |
| def main(): | |
| st.title("智慧文件摘要") | |
| st.markdown("上傳文本檔案,生成繁中重點摘要") | |
| # 讀取 API_KEY 從 Environment Variables | |
| api_key = os.getenv("TOGETHER_API_KEY") | |
| if not api_key: | |
| st.error("請設定 Together AI API_KEY!") | |
| return | |
| # 讓用戶上傳文件 | |
| uploaded_file = st.file_uploader("上傳 txt 文件", type=["txt"]) | |
| if not uploaded_file: | |
| st.info("請選擇文件...") | |
| return | |
| # 讀取文件內容 | |
| content = uploaded_file.read().decode("utf-8") | |
| # 生成摘要 | |
| model = load_model() | |
| response = model([{"role": "user", "content": "針對本文幫我生成繁中重點摘要並包含Markdown:" + content}]) | |
| summary = str(response.content) | |
| # 顯示結果 | |
| st.markdown("### 生成的摘要如下:") | |
| st.markdown(summary) | |
| if __name__ == "__main__": | |
| main() | |