Spaces:
Runtime error
Runtime error
rishikeshF
commited on
Commit
·
61285e6
1
Parent(s):
672a27c
Add application file
Browse files- app.py +74 -0
- requirements.txt +0 -0
app.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
from gtts import gTTS
|
4 |
+
from PIL import Image
|
5 |
+
import time
|
6 |
+
#from playsound import playsound
|
7 |
+
#from pydub import AudioSegment
|
8 |
+
#from preferredsoundplayer import soundplay
|
9 |
+
|
10 |
+
#@st.cache()
|
11 |
+
@st.cache(allow_output_mutation=True)
|
12 |
+
def load_model():
|
13 |
+
"""Retrieves the trained model"""
|
14 |
+
model = pipeline('image-to-text')
|
15 |
+
return model
|
16 |
+
|
17 |
+
def main():
|
18 |
+
caption = load_model()
|
19 |
+
st.title("Welcome to image to speech app")
|
20 |
+
instructions = """Click an image using inbuilt camera
|
21 |
+
or upload an image file"""
|
22 |
+
st.write(instructions)
|
23 |
+
|
24 |
+
img = None
|
25 |
+
pictureCam = st.camera_input("Take a picture")
|
26 |
+
pictureUpload = st.file_uploader('Upload An Image')
|
27 |
+
|
28 |
+
if pictureCam :
|
29 |
+
st.write('clicked image from webcam')
|
30 |
+
st.image(pictureCam)
|
31 |
+
img = Image.open(pictureCam)
|
32 |
+
elif pictureUpload :
|
33 |
+
st.write('uploaded image from device')
|
34 |
+
st.image(pictureUpload)
|
35 |
+
img = Image.open(pictureUpload)
|
36 |
+
|
37 |
+
if img is not None :
|
38 |
+
description = caption(img)
|
39 |
+
generated_text = description[0]['generated_text']
|
40 |
+
st.write(generated_text)
|
41 |
+
generated_audio = gTTS(generated_text)
|
42 |
+
generated_audio.save('demo.mp3')
|
43 |
+
|
44 |
+
audio_file = open(‘demo.mp3’, ‘rb’)
|
45 |
+
audio_bytes = audio_file.read()
|
46 |
+
st.audio(audio_bytes, format=‘audio/ogg’,start_time=0)
|
47 |
+
|
48 |
+
#html_string = """
|
49 |
+
#<audio controls autoplay>
|
50 |
+
# <source src="demo.mp3" type="audio/mp3">
|
51 |
+
#</audio>
|
52 |
+
#"""
|
53 |
+
#sound = st.empty()
|
54 |
+
#sound.markdown(html_string, unsafe_allow_html=True) # will display a st.audio with the sound you specified in the "src" of the html_string and autoplay it
|
55 |
+
#time.sleep(2) # wait for 2 seconds to finish the playing of the audio
|
56 |
+
#sound.empty() # optionally delete the element afterwards
|
57 |
+
|
58 |
+
#sound = AudioSegment.from_mp3("demo.mp3")
|
59 |
+
#sound.export("demo.wav", format="wav")
|
60 |
+
#soundplay("demo.mp3")
|
61 |
+
#playsound('demo.mp3')
|
62 |
+
#audio_file = open('demo.wav', 'rb')
|
63 |
+
#audio_bytes = audio_file.read()
|
64 |
+
#st.audio(audio_bytes, format='audio/wav')
|
65 |
+
|
66 |
+
|
67 |
+
if __name__ == '__main__' :
|
68 |
+
main()
|
69 |
+
|
70 |
+
import streamlit as st
|
71 |
+
import time
|
72 |
+
|
73 |
+
|
74 |
+
|
requirements.txt
ADDED
Binary file (1.09 kB). View file
|
|