Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from smolagents import LiteLLMModel
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
def load_model():
|
| 6 |
+
MODEL_NAMES = [
|
| 7 |
+
"Qwen/QwQ-32B", # 免費使用
|
| 8 |
+
]
|
| 9 |
+
model = LiteLLMModel(
|
| 10 |
+
"together_ai" + "/" + MODEL_NAMES[0],
|
| 11 |
+
temperature=0.2,
|
| 12 |
+
api_key=os.getenv("TOGETHER_API_KEY")
|
| 13 |
+
)
|
| 14 |
+
return model
|
| 15 |
+
|
| 16 |
+
def main():
|
| 17 |
+
st.title("文件摘要工具")
|
| 18 |
+
st.markdown("上傳文本檔案,生成繁中重點摘要")
|
| 19 |
+
|
| 20 |
+
# 讀取 API_KEY 從 Environment Variables
|
| 21 |
+
api_key = os.getenv("TOGETHER_API_KEY")
|
| 22 |
+
if not api_key:
|
| 23 |
+
st.error("請設定 Together AI API_KEY!")
|
| 24 |
+
return
|
| 25 |
+
|
| 26 |
+
# 讓用戶上傳文件
|
| 27 |
+
uploaded_file = st.file_uploader("上傳 txt 文件", type=["txt"])
|
| 28 |
+
if not uploaded_file:
|
| 29 |
+
st.info("請選擇文件inheritdoc...")
|
| 30 |
+
return
|
| 31 |
+
|
| 32 |
+
# 讀取文件內容
|
| 33 |
+
content = uploaded_file.read().decode("utf-8")
|
| 34 |
+
|
| 35 |
+
# 生成摘要
|
| 36 |
+
model = load_model()
|
| 37 |
+
response = model([{"role": "user", "content": "針對本文幫我生成繁中重點摘要並包含Markdown:" + content}])
|
| 38 |
+
summary = str(response.content)
|
| 39 |
+
|
| 40 |
+
# 顯示結果
|
| 41 |
+
st.markdown("### 生成的摘要如下:")
|
| 42 |
+
st.markdown(summary)
|
| 43 |
+
|
| 44 |
+
if __name__ == "__main__":
|
| 45 |
+
main()
|