cloud26
Feature/add wechat support (#24)
09a337f unverified
Raw
History Blame Contribute Delete
3.2 kB
import gradio as gr
from fastapi import FastAPI
from edu_assistant import version
from webui.coding_problem import CodingProblemUI
from webui.qa import QaUI
app = FastAPI()
demo = gr.Blocks(title="Codedog Edu Assistant", theme="gradio/soft")
qa_ui = QaUI()
cp_ui = CodingProblemUI()
def apply_cfg(
gpt4_flags: list[int],
qa_instruction: str,
cp_instruction: str,
cp_first_question: str,
qa_knowledge: str,
cp_knowledge: str,
):
qa_ui.ui_reload(
instruction=qa_instruction,
knowledge_name=qa_knowledge,
enable_gpt4=0 in gpt4_flags,
)
cp_ui.ui_reload(
instruction=cp_instruction,
first_question=cp_first_question,
knowledge_name=cp_knowledge,
enable_gpt4=1 in gpt4_flags,
)
demo.render()
gr.update()
gr.Info("更新配置成功")
def default_cfg():
qa_ui.ui_reload()
cp_ui.ui_reload()
demo.render()
gr.update()
gr.Info("恢复默认配置成功")
def get_gpt4_flags():
result = []
if qa_ui.enable_gpt4:
result.append("答疑")
if cp_ui.enable_gpt4:
result.append("做题")
return result
with demo:
with gr.Row():
gr.Markdown(f"# Codedog Edu Assistant v{version.VERSION}")
with gr.Tab(label="答疑"):
qa_ui.ui_render()
with gr.Tab(label="做题"):
cp_ui.ui_render()
with gr.Tab(label="设置"):
with gr.Row():
gr.Markdown("## Prompt 设置")
with gr.Row():
qa_instruction = gr.Textbox(
label="答疑指示Prompt", lines=5, max_lines=20, value=qa_ui.get_instruction, interactive=True
)
with gr.Row():
cp_instruction = gr.Textbox(
label="做题指示Prompt", lines=5, max_lines=20, value=cp_ui.get_instruction, interactive=True
)
with gr.Row():
cp_first_question = gr.Textbox(
label="判题Prompt", lines=5, max_lines=20, value=cp_ui.get_first_question, interactive=True
)
with gr.Row():
with gr.Column(scale=1):
gr.Markdown("## Open AI 设置")
with gr.Column(scale=2):
gpt4_flags = gr.CheckboxGroup(
value=get_gpt4_flags, choices=["答疑", "做题"], label="启用GPT4", type="index", interactive=True
)
with gr.Row():
gr.Markdown("## 知识库设置")
qa_knowledge = gr.Textbox(value=qa_ui.knowledge, label="答疑知识库", interactive=True)
cp_knowledge = gr.Textbox(value=cp_ui.knowledge, label="做题知识库", interactive=True)
with gr.Row():
default_btn = gr.Button(value="恢复默认配置", interactive=True, scale=1)
apply_btn = gr.Button(value="更新配置", interactive=True, variant="primary", scale=1)
default_btn.click(default_cfg, [], [])
apply_btn.click(
apply_cfg, [gpt4_flags, qa_instruction, cp_instruction, cp_first_question, qa_knowledge, cp_knowledge], []
)
demo.queue()
# app = gr.mount_gradio_app(app, demo, path="/")
if __name__ == "__main__":
demo.launch()
# uvicorn.run(app, port=7860)