txh17 commited on
Commit
d9e2fc3
·
verified ·
1 Parent(s): b66b356

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -35
app.py CHANGED
@@ -1,42 +1,17 @@
1
  import gradio as gr
2
- from model import load_stable_diffusion_model, load_gpt_model, generate_image_from_prompt, generate_prompt
3
- from utils import load_whisper_model, transcribe_audio
4
 
5
- # 加载模型
6
- stable_diff_pipe = load_stable_diffusion_model()
7
- gpt_model = load_gpt_model()
8
- whisper_model = load_whisper_model()
9
-
10
- # 生成图像和提示
11
- def generate_response(description):
12
  # 生成提示
13
- prompt = generate_prompt(gpt_model, description)
14
  # 生成图像
15
- image = generate_image_from_prompt(stable_diff_pipe, prompt)
16
  return prompt, image
17
 
18
- # 语音输入和图像生成
19
- def handle_audio(audio_file):
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
+