GTX98CZ's picture
FIX / demo.launch(ssr_mode=False)
4be48bd
Raw
History Blame Contribute Delete
3.15 kB
import spaces
import gradio as gr
import asyncio
import json
from services.speak_analyze_v7 import compute_gop_analysis_word_v7
@spaces.GPU(duration=60)
def analyze_speech_ui(audio_path: str, target_text: str) -> str:
if not audio_path or not target_text:
return "⚠️ 請提供音訊檔與目標文字!"
result = asyncio.run(compute_gop_analysis_word_v7(audio_path, target_text))
return json.dumps(result, ensure_ascii=False, indent=2)
with gr.Blocks(title="法語發音品質評估系統") as demo:
gr.Markdown("## 🇫🇷 法語發音品質評估系統")
with gr.Row():
with gr.Column():
text_input = gr.Textbox(label="目標法文文字", value="bonjour")
audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath")
submit_btn = gr.Button("🚀 開始分析發音", variant="primary")
with gr.Column():
text_output = gr.Code(label="分析結果 (JSON)", language="json")
submit_btn.click(fn=analyze_speech_ui, inputs=[audio_input, text_input], outputs=text_output)
demo.queue()
demo.launch(ssr_mode=False)
# import spaces
# print(">>> [2] spaces 已 import", flush=True)
# import gradio as gr
# print(">>> [3] gradio 已 import", flush=True)
# from fastapi import FastAPI
# from fastapi.middleware.cors import CORSMiddleware
# print(">>> [4] fastapi 已 import", flush=True)
# import asyncio
# import json
# import uvicorn
# from services.speak_analyze_v7 import compute_gop_analysis_word_v7
# print(">>> [5] speak_analyze_v7 已 import 成功", flush=True)
# app = FastAPI(title="French Pronunciation Analysis API")
# print(">>> [6] FastAPI app 已建立", flush=True)
# app.add_middleware(
# CORSMiddleware,
# allow_origins=["*"],
# allow_credentials=True,
# allow_methods=["*"],
# allow_headers=["*"],
# )
# @spaces.GPU(duration=60)
# def analyze_speech_ui(audio_path: str, target_text: str) -> str:
# if not audio_path or not target_text:
# return "⚠️ 請提供音訊檔與目標文字!"
# result = asyncio.run(compute_gop_analysis_word_v7(audio_path, target_text))
# return json.dumps(result, ensure_ascii=False, indent=2)
# with gr.Blocks(title="法語發音品質評估系統") as demo:
# gr.Markdown("## 🇫🇷 法語發音品質評估系統")
# with gr.Row():
# with gr.Column():
# text_input = gr.Textbox(label="目標法文文字", value="bonjour")
# audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath")
# submit_btn = gr.Button("🚀 開始分析發音", variant="primary")
# with gr.Column():
# text_output = gr.Code(label="分析結果 (JSON)", language="json")
# submit_btn.click(
# fn=analyze_speech_ui,
# inputs=[audio_input, text_input],
# outputs=text_output,
# )
# print(">>> [7] 准备 mount gradio", flush=True)
# app = gr.mount_gradio_app(app, demo, path="/")
# print(">>> [8] mount 完成,app.py 执行到底了", flush=True)
# if __name__ == "__main__":
# uvicorn.run(app, host="0.0.0.0", port=7860)