Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,9 +6,9 @@ import time
|
|
| 6 |
|
| 7 |
@st.cache(allow_output_mutation=True)
|
| 8 |
def load_model():
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
|
| 13 |
def main():
|
| 14 |
caption = load_model()
|
|
@@ -21,23 +21,23 @@ def main():
|
|
| 21 |
pictureUpload = st.file_uploader('Upload An Image')
|
| 22 |
|
| 23 |
if pictureCam :
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
elif pictureUpload :
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
|
| 32 |
if img is not None :
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
if __name__ == '__main__' :
|
| 43 |
main()
|
|
|
|
| 6 |
|
| 7 |
@st.cache(allow_output_mutation=True)
|
| 8 |
def load_model():
|
| 9 |
+
"""Retrieves the trained model"""
|
| 10 |
+
model = pipeline('image-to-text')
|
| 11 |
+
return model
|
| 12 |
|
| 13 |
def main():
|
| 14 |
caption = load_model()
|
|
|
|
| 21 |
pictureUpload = st.file_uploader('Upload An Image')
|
| 22 |
|
| 23 |
if pictureCam :
|
| 24 |
+
st.write('clicked image from webcam')
|
| 25 |
+
st.image(pictureCam)
|
| 26 |
+
img = Image.open(pictureCam)
|
| 27 |
elif pictureUpload :
|
| 28 |
+
st.write('uploaded image from device')
|
| 29 |
+
st.image(pictureUpload)
|
| 30 |
+
img = Image.open(pictureUpload)
|
| 31 |
|
| 32 |
if img is not None :
|
| 33 |
+
description = caption(img)
|
| 34 |
+
generated_text = description[0]['generated_text']
|
| 35 |
+
st.write(generated_text)
|
| 36 |
+
generated_audio = gTTS(generated_text)
|
| 37 |
+
generated_audio.save('demo.mp3')
|
| 38 |
+
audio_file = open('demo.mp3', 'rb')
|
| 39 |
+
audio_bytes = audio_file.read()
|
| 40 |
+
st.audio(audio_bytes, format='audio/ogg',start_time=0)
|
| 41 |
|
| 42 |
if __name__ == '__main__' :
|
| 43 |
main()
|