Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,27 +18,26 @@ def main():
|
|
18 |
image = st.file_uploader("Upload an image", type=["jpg", "png"])
|
19 |
question = st.text_input("Enter your question")
|
20 |
|
21 |
-
|
|
|
|
|
|
|
22 |
# 将上传的文件转换为 PIL 图片
|
23 |
image = Image.open(io.BytesIO(image.getvalue()))
|
24 |
|
25 |
# 对用户上传的图片和问题进行视觉问题回答
|
26 |
vqa_result = vqa_pipeline({"image": image, "question": question})
|
27 |
-
if vqa_result
|
28 |
-
answer = "No answer here!"
|
29 |
-
else:
|
30 |
answer = vqa_result[0]['answer'] # 获取回答
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
st.audio(audio_data, format="audio/ogg")
|
41 |
-
|
42 |
|
43 |
|
44 |
if __name__ == "__main__":
|
|
|
18 |
image = st.file_uploader("Upload an image", type=["jpg", "png"])
|
19 |
question = st.text_input("Enter your question")
|
20 |
|
21 |
+
# 添加按钮以控制是否执行视觉问题回答
|
22 |
+
run_vqa = st.button('Run Visual Question Answering')
|
23 |
+
|
24 |
+
if image and question and run_vqa:
|
25 |
# 将上传的文件转换为 PIL 图片
|
26 |
image = Image.open(io.BytesIO(image.getvalue()))
|
27 |
|
28 |
# 对用户上传的图片和问题进行视觉问题回答
|
29 |
vqa_result = vqa_pipeline({"image": image, "question": question})
|
30 |
+
if vqa_result: # 确保返回结果不为空
|
|
|
|
|
31 |
answer = vqa_result[0]['answer'] # 获取回答
|
32 |
+
st.write(f"Answer: {answer}") # 显示回答
|
33 |
+
|
34 |
+
# 添加按钮以控制是否将回答转换为音频并播放
|
35 |
+
run_tts = st.button('Convert Answer to Audio')
|
36 |
+
if run_tts:
|
37 |
+
# 将回答转换为音频
|
38 |
+
tts_result = tts_pipeline(answer)
|
39 |
+
audio_data = tts_result['audio'] # 获取音频数据
|
40 |
+
st.audio(audio_data, format="audio/ogg")
|
|
|
|
|
41 |
|
42 |
|
43 |
if __name__ == "__main__":
|