Update app.py
Browse files
app.py
CHANGED
|
@@ -1,42 +1,17 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
from
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
whisper_model = load_whisper_model()
|
| 9 |
-
|
| 10 |
-
# 生成图像和提示
|
| 11 |
-
def generate_response(description):
|
| 12 |
# 生成提示
|
| 13 |
-
prompt = generate_prompt(
|
| 14 |
# 生成图像
|
| 15 |
-
image = generate_image_from_prompt(
|
| 16 |
return prompt, image
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
text = transcribe_audio(whisper_model, audio_file)
|
| 21 |
-
return generate_response(text)
|
| 22 |
-
|
| 23 |
-
# Gradio界面设置
|
| 24 |
-
iface = gr.Interface(
|
| 25 |
-
fn=generate_response,
|
| 26 |
-
inputs="text",
|
| 27 |
-
outputs=["text", "image"],
|
| 28 |
-
title="图像生成器",
|
| 29 |
-
description="输入简短的描述,生成详细提示并生成图像。"
|
| 30 |
-
)
|
| 31 |
-
|
| 32 |
-
# 语音输入功能
|
| 33 |
-
iface_with_audio = gr.Interface(
|
| 34 |
-
fn=handle_audio,
|
| 35 |
-
inputs=gr.Audio(source="microphone", type="filepath"),
|
| 36 |
-
outputs=["text", "image"],
|
| 37 |
-
title="语音图像生成器",
|
| 38 |
-
description="通过语音输入来生成图像。"
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
-
# 运行界面
|
| 42 |
iface.launch()
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from whisper_model import transcribe_audio
|
| 3 |
+
from model import generate_prompt, generate_image_from_prompt
|
| 4 |
|
| 5 |
+
def gradio_interface_with_audio(audio_file):
|
| 6 |
+
""" Gradio 界面函数,支持语音输入 """
|
| 7 |
+
description = transcribe_audio(audio_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# 生成提示
|
| 9 |
+
prompt = generate_prompt(description)
|
| 10 |
# 生成图像
|
| 11 |
+
image = generate_image_from_prompt(prompt)
|
| 12 |
return prompt, image
|
| 13 |
|
| 14 |
+
# 创建 Gradio 界面
|
| 15 |
+
iface = gr.Interface(fn=gradio_interface_with_audio, inputs="audio", outputs=["text", "image"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
iface.launch()
|
| 17 |
+
|