diff --git a/.gitignore b/.gitignore index 19efb5a940189d778f1f8cbc68122a292e5c5aa7..c5cc22a30ae8b7864be9d01e8f9257ff17febd74 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ resource.zip faq .gradio *.old -get_audio.py \ No newline at end of file +get_audio.py +.vscode \ No newline at end of file diff --git a/api.py b/api.py index a8c67b5dfb54085b7185eec5e9855700db6e88cc..f1fef926229ae330a3f0c52a56367278587a482e 100644 --- a/api.py +++ b/api.py @@ -3,10 +3,21 @@ import pickle from datetime import datetime from pathlib import Path -from fish_audio_sdk import Session, TTSRequest +from fishaudio import FishAudio +from fishaudio.utils import save from openai import OpenAI from tenacity import retry, stop_after_attempt, wait_exponential +try: + from dotenv import load_dotenv + + env_path = Path(os.path.dirname(__file__)) / ".env" + if env_path.exists(): + load_dotenv(env_path) +except ImportError: + pass + +# params INFO_audio_ID_dict = { "matsu": os.getenv("INFO_audio_matsu"), "ken": os.getenv("INFO_audio_ken"), @@ -18,7 +29,7 @@ INFO_audio_ID_dict = { client = OpenAI(api_key=os.getenv("gpt")) # -audio_client = Session(os.getenv("audio")) +audio_client = FishAudio(api_key=os.getenv("audio")) PKL_FILE = "./resource/knowledge_data.pkl" @@ -42,22 +53,11 @@ def save_pkl(file_name, data): pickle.dump(sorted_data, f) -try: - from dotenv import load_dotenv - - env_path = Path(os.path.dirname(__file__)) / ".env" - if env_path.exists(): - load_dotenv(env_path) -except ImportError: - pass -# params - - @retry( stop=stop_after_attempt(5), wait=wait_exponential(multiplier=1, min=2, max=10), ) -def generate_item(prompt, sys_prompt, model="gpt-4.1-mini", temperature=1.0): +def generate_item(prompt, sys_prompt, model="gpt-5.4-mini", temperature=1.0): # print("prompt=", prompt) # print("temperature=", temperature) response = client.chat.completions.create( @@ -90,13 +90,20 @@ def get_embedding(text): def audio_text(text, audio_path, speaker_id): # TODO change speaker # print(speaker_id, ":", INFO_audio_ID_dict[speaker_id]) - - with open(audio_path, "wb") as f: - for chunk in audio_client.tts( - TTSRequest( - reference_id=INFO_audio_ID_dict[speaker_id], text=text, latency="normal" - ), - backend="s1", - ): - f.write(chunk) + audio = audio_client.tts.convert( + text=text, + reference_id=INFO_audio_ID_dict[speaker_id], + format="mp3", + model="s2-pro", + ) + save(audio, audio_path) + + # with open(audio_path, "wb") as f: + # for chunk in audio_client.tts( + # TTSRequest( + # reference_id=INFO_audio_ID_dict[speaker_id], text=text, latency="normal" + # ), + # backend="s1", + # ): + # f.write(chunk) return audio_path diff --git a/app.py b/app.py index d61c732a33dac9bc0b8d956f9ddfd3a7bbc86ca6..d42bbe7e514ac09e14603fa4815a90a6f5428e6c 100644 --- a/app.py +++ b/app.py @@ -79,13 +79,11 @@ def answer_question( def run_audio_answer(): run_audio_path = audio_text(answer_text, audio_file_path, speaker_flag) audio_str = base64.b64encode(open(run_audio_path, "rb").read()).decode("utf-8") - history[-2]["content"] = gr.HTML( - f""" + history[-2]["content"] = gr.HTML(f""" - """ - ) + """) history[-2]["metadata"] = {"title": "🎧 音声返信", "status": "done"} if not audio_flag: @@ -202,7 +200,7 @@ with gr.Blocks(title="勉強会", css=custom_css, head=custom_head, js=js_func) bubble_full_width=False, avatar_images=( None, - "https://cdn.profile-image.st-hatena.com/users/saratoga623/profile.png?1728512391", + "https://assets.st-note.com/production/uploads/images/212145872/profile_ec44d8ebf5cfcb95f777ad3dacdeaacf.png?fit=bounds&format=jpeg&quality=85&width=330", ), ) diff --git a/blog_class.py b/blog_class.py index b64482e5226605968771dbab0681e3f744c74841..fc5c07fa4f5463f14ac2e1f848d4bc89a0844e18 100644 --- a/blog_class.py +++ b/blog_class.py @@ -158,7 +158,7 @@ class knowledge_class: ) print("user_prompt:", user_prompt) answer_text = generate_item( - user_prompt, SYS_Prompt, model="gpt-4.1", temperature=temperature + user_prompt, SYS_Prompt, model="gpt-5.4", temperature=temperature ) audio_filename = save_md_and_get_audio(user_prompt, answer_text) return answer_text, info_title, audio_filename @@ -216,7 +216,7 @@ class knowledge_class: chat_history=chat_history_str, question=new_query ) - rewrite_question = generate_item(rw_prompt, REWRITE_SYS_Prompt, model="gpt-4.1") + rewrite_question = generate_item(rw_prompt, REWRITE_SYS_Prompt, model="gpt-5.4") print("rewrite_question:", rewrite_question) # get rewrite question @@ -244,7 +244,7 @@ class knowledge_class: answer_text = generate_item( user_prompt, SYS_Prompt, - model="gpt-4.1", + model="gpt-5.4", temperature=temperature, ) audio_filename = save_md_and_get_audio(user_prompt, answer_text) diff --git a/design.py b/design.py index 29932d1d8b14212f07e13164ed4a5bc834c12c1f..422354b7a2ef0c57865c07e103e4a29d48f95af7 100644 --- a/design.py +++ b/design.py @@ -70,7 +70,7 @@ function refresh() { title_html = """