Final_version / app.py
Steven-GU-Yu-Di's picture
Update app.py
a12eb5f verified
raw
history blame
799 Bytes
import streamlit as st
from transformers import pipeline
# 加载 Visual Question Answering 模型 microsoft/git-base-vqav2
vqa_pipeline = pipeline("text2text-generation", model="microsoft/git-base-vqav2")
# 加载文本到语音模型
text_to_speech_pipeline = pipeline("text-to-speech", model="microsoft/speecht5_tts")
def main():
st.title("Visual Question Answering with Text-to-Speech")
image_path = st.text_input("Enter image path:")
question = st.text_input("Enter your question:")
if st.button("Get Answer"):
answer = vqa_pipeline(question, image_path)[0]['generated_text']
audio_data = text_to_speech_pipeline(answer)
st.write("Answer:", answer)
st.audio(audio_data[0]["audio"], format='audio/wav')
if __name__ == '__main__':
main()