Spaces:
Runtime error
Runtime error
Steven-GU-Yu-Di
commited on
Commit
•
16ac1d6
1
Parent(s):
c85c703
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,35 @@
|
|
1 |
-
import
|
2 |
-
from transformers import pipeline
|
3 |
-
from PIL import Image
|
4 |
|
5 |
-
|
6 |
-
|
7 |
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
# Load the Text-to-Speech (TTS) model
|
10 |
-
tts = pipeline("text-to-audio", model="Steven-GU-Yu-Di/Text-to-Speech")
|
11 |
|
|
|
|
|
12 |
|
13 |
-
|
14 |
-
st.title("Visual Question Answering
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
question_input = st.text_input("Enter Question")
|
19 |
|
20 |
-
# Function to perform Visual Question Answering and Text-to-Speech
|
21 |
-
def perform_vqa_and_tts(image, question):
|
22 |
-
if image is not None and question:
|
23 |
-
image = Image.open(image)
|
24 |
-
st.image(image, caption="Uploaded Image", use_column_width=True)
|
25 |
-
st.write("Question:", question)
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
"context": "This is an image.",
|
31 |
-
}
|
32 |
-
vqa_output = vqa_model(image=image, **vqa_input)
|
33 |
-
answer = vqa_output['answer']
|
34 |
-
st.write("Answer:", answer)
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
perform_vqa_and_tts(uploaded_image, question_input)
|
|
|
1 |
+
import os
|
|
|
|
|
2 |
|
3 |
+
os.system('pip install torch')
|
4 |
+
os.system('pip install transformers')
|
5 |
|
6 |
+
from PIL import Image
|
7 |
+
import io
|
8 |
+
import streamlit as st
|
9 |
+
from transformers import pipeline
|
10 |
|
|
|
|
|
11 |
|
12 |
+
vqa_pipeline = pipeline("visual-question-answering", model="microsoft/git-base-vqav2")
|
13 |
+
tts_pipeline = pipeline("text-to-speech", "suno/bark")
|
14 |
|
15 |
+
def main():
|
16 |
+
st.title("Visual Question Answering & Text-to-Audio App")
|
17 |
+
|
18 |
+
image = st.file_uploader("Upload an image", type=["jpg", "png"])
|
19 |
+
question = st.text_input("Enter your question")
|
20 |
|
21 |
+
if image and question:
|
22 |
+
image = Image.open(io.BytesIO(image.getvalue()))
|
|
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
vqa_result = vqa_pipeline({"image": image, "question": question})
|
26 |
+
answer = vqa_result[0]['answer']
|
27 |
+
st.write(f"Answer: {answer}")
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
+
if st.button("Convert Answer to Audio"):
|
30 |
+
tts_result = tts_pipeline(answer)
|
31 |
+
audio_data = tts_result['audio']
|
32 |
+
st.audio(audio_data, format="audio/ogg")
|
33 |
|
34 |
+
if __name__ == "__main__":
|
35 |
+
main()
|
|