Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,79 +1,58 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
})
|
58 |
-
|
59 |
-
status.append("✅ 完成!")
|
60 |
-
return results, status
|
61 |
-
|
62 |
-
except Exception as e:
|
63 |
-
status.append(f"❌ 發生錯誤: {str(e)}")
|
64 |
-
return [], status
|
65 |
-
|
66 |
-
# Gradio 介面
|
67 |
-
demo = gr.Interface(
|
68 |
-
fn=get_words_with_sentences,
|
69 |
-
inputs=[
|
70 |
-
gr.Dropdown(choices=get_sources(), value="common3000", label="選擇單字庫", interactive=True, show_clear_button=False),
|
71 |
-
gr.Number(value=10, label="抽幾個單字")
|
72 |
-
],
|
73 |
-
outputs=[
|
74 |
-
gr.JSON(label="生成結果"),
|
75 |
-
gr.JSON(label="生成進度")
|
76 |
-
]
|
77 |
-
)
|
78 |
|
79 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from vocab import get_sources, get_words_with_sentences
|
3 |
+
|
4 |
+
with gr.Blocks() as demo:
|
5 |
+
gr.Markdown(
|
6 |
+
"""
|
7 |
+
# 📖 英文單字隨機抽取 & GPT 例句生成 API
|
8 |
+
|
9 |
+
## 📝 專案簡介
|
10 |
+
本專案提供一個 API 服務,能夠從不同的單字庫隨機抽取單字,並使用開源語言模型自動生成例句。
|
11 |
+
適合作為 LINE 單字推播、自學工具、英文教學輔助等用途。
|
12 |
+
|
13 |
+
## ⚙️ 主要功能
|
14 |
+
- 支援從多個單字庫中選擇,如:`common3000`, `business_words`。
|
15 |
+
- 可自訂抽取單字數量。
|
16 |
+
- 每個單字自動生成一個簡單的英文例句,適合初學者學習。
|
17 |
+
|
18 |
+
## 📚 使用方式
|
19 |
+
1. 選擇單字庫(例如:`common3000`)。
|
20 |
+
2. 設定抽取單字數量(例如:10個)。
|
21 |
+
3. 點擊「生成例句」按鈕,即可獲得單字 + 音標 + 例句。
|
22 |
+
|
23 |
+
## 🗂️ 資料來源
|
24 |
+
- **common3000**:常用3000單字表,附音標。
|
25 |
+
- 未來可能會有更多單字庫新增至 `/data/` 資料夾。(可能啦!
|
26 |
+
|
27 |
+
## 🛠️ 技術架構
|
28 |
+
- **Gradio Blocks** 前端介面 + API。
|
29 |
+
- **Hugging Face Transformers** 語言模型:
|
30 |
+
- 模型:`EleutherAI/pythia-410m`(小型 GPT 模型)
|
31 |
+
|
32 |
+
## 👨💻 開發者資訊
|
33 |
+
- 開發者:余彦志 (大宇 ian)
|
34 |
+
- 信箱:dayuian@hotmail.com
|
35 |
+
- GitHub:[https://github.com/dayuian](https://github.com/dayuian)
|
36 |
+
"""
|
37 |
+
)
|
38 |
+
|
39 |
+
source_dropdown = gr.Dropdown(
|
40 |
+
choices=get_sources(),
|
41 |
+
value="common3000",
|
42 |
+
label="選擇單字庫",
|
43 |
+
interactive=True
|
44 |
+
)
|
45 |
+
|
46 |
+
num_input = gr.Number(value=10, label="抽幾個單字")
|
47 |
+
result_output = gr.HTML(label="生成結果")
|
48 |
+
status_output = gr.Textbox(label="狀態更新", lines=8, interactive=False)
|
49 |
+
|
50 |
+
submit_btn = gr.Button("生成例句")
|
51 |
+
|
52 |
+
submit_btn.click(
|
53 |
+
fn=get_words_with_sentences,
|
54 |
+
inputs=[source_dropdown, num_input],
|
55 |
+
outputs=[result_output, status_output]
|
56 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
demo.launch()
|