Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,8 +3,6 @@ import random
|
|
| 3 |
from vocab import get_sources, get_words_from_source
|
| 4 |
from sentences import generate_sentences
|
| 5 |
from ai_sentence import MODEL_LIST
|
| 6 |
-
import random
|
| 7 |
-
|
| 8 |
|
| 9 |
def process_sentence(mode, word, source, num, use_ai, model_name):
|
| 10 |
try:
|
|
@@ -29,9 +27,8 @@ def process_sentence(mode, word, source, num, use_ai, model_name):
|
|
| 29 |
except Exception as e:
|
| 30 |
return f"<p style='color:red;'>❌ 發生錯誤:{str(e)}</p>", f"錯誤:{str(e)}"
|
| 31 |
|
| 32 |
-
|
| 33 |
with gr.Blocks(css="""
|
| 34 |
-
|
| 35 |
.gradio-container { max-width: 800px; margin: auto; }
|
| 36 |
#generate-button.ai-active { background-color: #ff9800 !important; color: white !important; }
|
| 37 |
""") as demo:
|
|
@@ -57,7 +54,7 @@ with gr.Blocks(css="""
|
|
| 57 |
interactive=True
|
| 58 |
)
|
| 59 |
|
| 60 |
-
with gr.
|
| 61 |
word_input = gr.Textbox(label="輸入單字", visible=True)
|
| 62 |
num_input = gr.Number(label="抽取單字數量", value=5, visible=False)
|
| 63 |
source_dropdown = gr.Dropdown(
|
|
@@ -66,7 +63,7 @@ with gr.Blocks(css="""
|
|
| 66 |
label="選擇單字庫"
|
| 67 |
)
|
| 68 |
|
| 69 |
-
with gr.
|
| 70 |
use_ai_checkbox = gr.Checkbox(label="使用 AI 生成句子", elem_id="use-ai-checkbox")
|
| 71 |
model_dropdown = gr.Dropdown(
|
| 72 |
choices=MODEL_LIST,
|
|
@@ -81,7 +78,6 @@ with gr.Blocks(css="""
|
|
| 81 |
result_output = gr.HTML(label="結果")
|
| 82 |
status_output = gr.Textbox(label="處理狀態", interactive=False)
|
| 83 |
|
| 84 |
-
# 模式切換
|
| 85 |
def switch_mode(mode):
|
| 86 |
if mode == 'query':
|
| 87 |
return gr.update(visible=True), gr.update(visible=False)
|
|
@@ -94,11 +90,8 @@ with gr.Blocks(css="""
|
|
| 94 |
outputs=[word_input, num_input]
|
| 95 |
)
|
| 96 |
|
| 97 |
-
# 勾選 AI → 模型選擇顯示 + 按鈕變色
|
| 98 |
def toggle_ai_button(use_ai):
|
| 99 |
-
# 控制模型選單顯示
|
| 100 |
model_visibility = gr.update(visible=use_ai)
|
| 101 |
-
# 自定義 JS 變色
|
| 102 |
js_toggle_class = f"""
|
| 103 |
function toggleButtonClass() {{
|
| 104 |
const btn = document.getElementById('generate-button');
|
|
@@ -124,4 +117,4 @@ with gr.Blocks(css="""
|
|
| 124 |
outputs=[result_output, status_output]
|
| 125 |
)
|
| 126 |
|
| 127 |
-
demo.launch()
|
|
|
|
| 3 |
from vocab import get_sources, get_words_from_source
|
| 4 |
from sentences import generate_sentences
|
| 5 |
from ai_sentence import MODEL_LIST
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def process_sentence(mode, word, source, num, use_ai, model_name):
|
| 8 |
try:
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
return f"<p style='color:red;'>❌ 發生錯誤:{str(e)}</p>", f"錯誤:{str(e)}"
|
| 29 |
|
|
|
|
| 30 |
with gr.Blocks(css="""
|
| 31 |
+
#card-group { padding: 15px; border-radius: 12px; background-color: rgba(255, 255, 255, 0.05); box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); margin-bottom: 15px; }
|
| 32 |
.gradio-container { max-width: 800px; margin: auto; }
|
| 33 |
#generate-button.ai-active { background-color: #ff9800 !important; color: white !important; }
|
| 34 |
""") as demo:
|
|
|
|
| 54 |
interactive=True
|
| 55 |
)
|
| 56 |
|
| 57 |
+
with gr.Group(elem_id="card-group"):
|
| 58 |
word_input = gr.Textbox(label="輸入單字", visible=True)
|
| 59 |
num_input = gr.Number(label="抽取單字數量", value=5, visible=False)
|
| 60 |
source_dropdown = gr.Dropdown(
|
|
|
|
| 63 |
label="選擇單字庫"
|
| 64 |
)
|
| 65 |
|
| 66 |
+
with gr.Group(elem_id="card-group"):
|
| 67 |
use_ai_checkbox = gr.Checkbox(label="使用 AI 生成句子", elem_id="use-ai-checkbox")
|
| 68 |
model_dropdown = gr.Dropdown(
|
| 69 |
choices=MODEL_LIST,
|
|
|
|
| 78 |
result_output = gr.HTML(label="結果")
|
| 79 |
status_output = gr.Textbox(label="處理狀態", interactive=False)
|
| 80 |
|
|
|
|
| 81 |
def switch_mode(mode):
|
| 82 |
if mode == 'query':
|
| 83 |
return gr.update(visible=True), gr.update(visible=False)
|
|
|
|
| 90 |
outputs=[word_input, num_input]
|
| 91 |
)
|
| 92 |
|
|
|
|
| 93 |
def toggle_ai_button(use_ai):
|
|
|
|
| 94 |
model_visibility = gr.update(visible=use_ai)
|
|
|
|
| 95 |
js_toggle_class = f"""
|
| 96 |
function toggleButtonClass() {{
|
| 97 |
const btn = document.getElementById('generate-button');
|
|
|
|
| 117 |
outputs=[result_output, status_output]
|
| 118 |
)
|
| 119 |
|
| 120 |
+
demo.launch()
|