35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import gradio as gr
|
|
from typing import List, Dict
|
|
from sqlmodel import Session, select
|
|
from db import get_engine
|
|
from schema import APIProvider
|
|
import os
|
|
|
|
# 获取数据库引擎
|
|
engine = get_engine(os.path.join(os.path.dirname(__file__), "..", "workdir"))
|
|
|
|
def setting_page():
|
|
def get_providers() -> List[List[str]]:
|
|
with Session(engine) as session:
|
|
providers = session.exec(select(APIProvider)).all()
|
|
return [
|
|
[p.id, p.model_id, p.base_url, p.api_key or ""]
|
|
for p in providers
|
|
]
|
|
|
|
with gr.Blocks() as demo:
|
|
gr.Markdown("## API Provider 管理")
|
|
|
|
with gr.Row():
|
|
# API Provider列表
|
|
with gr.Column(scale=2):
|
|
provider_table = gr.DataFrame(
|
|
headers=["id" , "model id", "URL", "API Key"],
|
|
datatype=["number","str", "str", "str"],
|
|
interactive=True,
|
|
value=get_providers(),
|
|
wrap=True,
|
|
col_count=(4, "fixed")
|
|
)
|
|
|
|
return demo |