VocabLine / app.py
dayuian's picture
Update app.py
f7e4e7d verified
raw
history blame
2.25 kB
import gradio as gr
from vocab import get_sources, get_words_with_sentences
with gr.Blocks() as demo:
gr.Markdown(
"""
# 📖 英文單字隨機抽取 & GPT 例句生成 API
## 📝 專案簡介
本專案製作一個 API 服務,能夠從不同的單字庫隨機抽取單字,並使用開源語言模型自動生成例句。
未來適合作為 LINE 單字推播、自學工具、英文教學輔助等用途。
因為現在是免費模型,所以生成句子都很鳥,生成一次需要約一分鐘的時間,主要是測試用。
## ⚙️ 主要功能
- 支援從多個單字庫中選擇,如:`common3000`, `business_words`。
- 可自訂抽取單字數量。
- 每個單字自動生成一個簡單的英文例句,適合初學者學習。
## 📚 使用方式
1. 選擇單字庫(例如:`common3000`)。
2. 設定抽取單字數量(例如:10個)。
3. 點擊「生成例句」按鈕,即可獲得單字 + 音標 + 例句。
## 🗂️ 資料來源
- **common3000**:常用3000單字表,附音標。
- 未來可能會有更多單字庫新增至 `/data/` 資料夾。(可能啦!
## 🛠️ 技術架構
- **Gradio Blocks** 前端介面 + API。
- **Hugging Face Transformers** 語言模型:
- 模型:`EleutherAI/pythia-410m`(小型 GPT 模型)
## 👨‍💻 開發者資訊
- 開發者:余彦志 (大宇 ian)
- 信箱:[email protected]
- GitHub:[https://github.com/dayuian](https://github.com/dayuian)
"""
)
source_dropdown = gr.Dropdown(
choices=get_sources(),
value="common3000",
label="選擇單字庫",
interactive=True
)
num_input = gr.Number(value=10, label="抽幾個單字")
result_output = gr.HTML(label="生成結果")
status_output = gr.Textbox(label="狀態更新", lines=8, interactive=False)
submit_btn = gr.Button("生成例句")
submit_btn.click(
fn=get_words_with_sentences,
inputs=[source_dropdown, num_input],
outputs=[result_output, status_output]
)
demo.launch()