version 3.75 (#1702)
* Update version to 3.74 * Add support for Yi Model API (#1635) * 更新以支持零一万物模型 * 删除newbing * 修改config --------- Co-authored-by: binary-husky <qingxu.fu@outlook.com> * Refactor function signatures in bridge files * fix qwen api change * rename and ref functions * rename and move some cookie functions * 增加haiku模型,新增endpoint配置说明 (#1626) * haiku added * 新增haiku,新增endpoint配置说明 * Haiku added * 将说明同步至最新Endpoint --------- Co-authored-by: binary-husky <qingxu.fu@outlook.com> * private_upload目录下进行文件鉴权 (#1596) * private_upload目录下进行文件鉴权 * minor fastapi adjustment * Add logging functionality to enable saving conversation records * waiting to fix username retrieve * support 2rd web path * allow accessing default user dir --------- Co-authored-by: binary-husky <qingxu.fu@outlook.com> * remove yaml deps * fix favicon * fix abs path auth problem * forget to write a return * add `dashscope` to deps * fix GHSA-v9q9-xj86-953p * 用户名重叠越权访问patch (#1681) * add cohere model api access * cohere + can_multi_thread * fix block user access(fail) * fix fastapi bug * change cohere api endpoint * explain version * # fix com_zhipuglm.py illegal temperature problem (#1687) * Update com_zhipuglm.py # fix 用户在使用 zhipuai 界面时遇到了关于温度参数的非法参数错误 * allow store lm model dropdown * add a btn to reverse previous reset * remove extra fns * Add support for glm-4v model (#1700) * 修改chatglm3量化加载方式 (#1688) Co-authored-by: zym9804 <ren990603@gmail.com> * save chat stage 1 * consider null cookie situation * 在点击复制按钮时激活语音 * miss some parts * move all to js * done first stage * add edge tts * bug fix * bug fix * remove console log * bug fix * bug fix * bug fix * audio switch * update tts readme * remove tempfile when done * disable auto audio follow * avoid play queue update after shut up * feat: minimizing common.js * improve tts functionality * deterine whether the cached model is in choices * Add support for Ollama (#1740) * print err when doc2x not successful * add icon * adjust url for doc2x key version * prepare merge --------- Co-authored-by: Menghuan1918 <menghuan2003@outlook.com> Co-authored-by: Skyzayre <120616113+Skyzayre@users.noreply.github.com> Co-authored-by: XIao <46100050+Kilig947@users.noreply.github.com> Co-authored-by: Yuki <903728862@qq.com> Co-authored-by: zyren123 <91042213+zyren123@users.noreply.github.com> Co-authored-by: zym9804 <ren990603@gmail.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import json
|
||||
from typing import Callable
|
||||
|
||||
def load_web_cookie_cache__fn_builder(customize_btns, cookies, predefined_btns)->Callable:
|
||||
def load_web_cookie_cache(persistent_cookie_, cookies_):
|
||||
import gradio as gr
|
||||
@@ -22,7 +24,6 @@ def load_web_cookie_cache__fn_builder(customize_btns, cookies, predefined_btns)-
|
||||
return ret
|
||||
return load_web_cookie_cache
|
||||
|
||||
|
||||
def assign_btn__fn_builder(customize_btns, predefined_btns, cookies, web_cookie_cache)->Callable:
|
||||
def assign_btn(persistent_cookie_, cookies_, basic_btn_dropdown_, basic_fn_title, basic_fn_prefix, basic_fn_suffix, clean_up=False):
|
||||
import gradio as gr
|
||||
@@ -59,3 +60,29 @@ def assign_btn__fn_builder(customize_btns, predefined_btns, cookies, web_cookie_
|
||||
return ret
|
||||
return assign_btn
|
||||
|
||||
# cookies, web_cookie_cache = make_cookie_cache()
|
||||
def make_cookie_cache():
|
||||
# 定义 后端state(cookies)、前端(web_cookie_cache)两兄弟
|
||||
import gradio as gr
|
||||
from toolbox import load_chat_cookies
|
||||
# 定义cookies的后端state
|
||||
cookies = gr.State(load_chat_cookies())
|
||||
# 定义cookies的一个孪生的前端存储区(隐藏)
|
||||
web_cookie_cache = gr.Textbox(visible=False, elem_id="web_cookie_cache")
|
||||
return cookies, web_cookie_cache
|
||||
|
||||
# history, history_cache, history_cache_update = make_history_cache()
|
||||
def make_history_cache():
|
||||
# 定义 后端state(history)、前端(history_cache)、后端setter(history_cache_update)三兄弟
|
||||
import gradio as gr
|
||||
# 定义history的后端state
|
||||
history = gr.State([])
|
||||
# 定义history的一个孪生的前端存储区(隐藏)
|
||||
history_cache = gr.Textbox(visible=False, elem_id="history_cache")
|
||||
# 定义history_cache->history的更新方法(隐藏)。在触发这个按钮时,会先执行js代码更新history_cache,然后再执行python代码更新history
|
||||
def process_history_cache(history_cache):
|
||||
return json.loads(history_cache)
|
||||
# 另一种更简单的setter方法
|
||||
history_cache_update = gr.Button("", elem_id="elem_update_history", visible=False).click(
|
||||
process_history_cache, inputs=[history_cache], outputs=[history])
|
||||
return history, history_cache, history_cache_update
|
||||
|
||||
@@ -137,6 +137,47 @@ def start_app(app_block, CONCURRENT_COUNT, AUTHENTICATION, PORT, SSL_KEYFILE, SS
|
||||
return "越权访问!"
|
||||
return await endpoint(path_or_url, request)
|
||||
|
||||
TTS_TYPE = get_conf("TTS_TYPE")
|
||||
if TTS_TYPE != "DISABLE":
|
||||
# audio generation functionality
|
||||
import httpx
|
||||
from fastapi import FastAPI, Request, HTTPException
|
||||
from starlette.responses import Response
|
||||
async def forward_request(request: Request, method: str) -> Response:
|
||||
async with httpx.AsyncClient() as client:
|
||||
try:
|
||||
# Forward the request to the target service
|
||||
if TTS_TYPE == "EDGE_TTS":
|
||||
import tempfile
|
||||
import edge_tts
|
||||
import wave
|
||||
import uuid
|
||||
from pydub import AudioSegment
|
||||
json = await request.json()
|
||||
voice = get_conf("EDGE_TTS_VOICE")
|
||||
tts = edge_tts.Communicate(text=json['text'], voice=voice)
|
||||
temp_folder = tempfile.gettempdir()
|
||||
temp_file_name = str(uuid.uuid4().hex)
|
||||
temp_file = os.path.join(temp_folder, f'{temp_file_name}.mp3')
|
||||
await tts.save(temp_file)
|
||||
mp3_audio = AudioSegment.from_file(temp_file, format="mp3")
|
||||
mp3_audio.export(temp_file, format="wav")
|
||||
with open(temp_file, 'rb') as wav_file: t = wav_file.read()
|
||||
os.remove(temp_file)
|
||||
return Response(content=t)
|
||||
if TTS_TYPE == "LOCAL_SOVITS_API":
|
||||
# Forward the request to the target service
|
||||
TARGET_URL = get_conf("GPT_SOVITS_URL")
|
||||
body = await request.body()
|
||||
resp = await client.post(TARGET_URL, content=body, timeout=60)
|
||||
# Return the response from the target service
|
||||
return Response(content=resp.content, status_code=resp.status_code, headers=dict(resp.headers))
|
||||
except httpx.RequestError as e:
|
||||
raise HTTPException(status_code=400, detail=f"Request to the target service failed: {str(e)}")
|
||||
@gradio_app.post("/vits")
|
||||
async def forward_post_request(request: Request):
|
||||
return await forward_request(request, "POST")
|
||||
|
||||
# --- --- app_lifespan --- ---
|
||||
from contextlib import asynccontextmanager
|
||||
@asynccontextmanager
|
||||
|
||||
Reference in New Issue
Block a user