Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -80,55 +80,68 @@ def txt2img(text, style="realistic"):
|
|
80 |
|
81 |
st.sidebar.title("Choose the task")
|
82 |
|
83 |
-
#
|
84 |
-
def
|
85 |
-
st.title("
|
86 |
-
st.write("
|
87 |
-
|
88 |
-
with st.expander("Audio Story"):
|
89 |
-
st.write(page_title="π¨ Image-to-Audio Story π§", page_icon="πΌοΈ")
|
90 |
-
st.title("Turn the Image into Audio Story")
|
91 |
-
|
92 |
-
uploaded_file = st.file_uploader("# π· Upload an image...", type=["jpg", "jpeg", "png"])
|
93 |
-
|
94 |
-
if uploaded_file is not None:
|
95 |
-
bytes_data = uploaded_file.read()
|
96 |
-
with open("uploaded_image.jpg", "wb") as file:
|
97 |
-
file.write(bytes_data)
|
98 |
-
|
99 |
-
st.image(uploaded_file, caption='πΌοΈ Uploaded Image', use_column_width=True)
|
100 |
-
|
101 |
-
with st.spinner("## π€ AI is at Work! "):
|
102 |
-
scenario = img2txt("uploaded_image.jpg") # Extracts text from the image
|
103 |
-
story = generate_story(scenario, llm) # Generates a story based on the image text, LLM params
|
104 |
-
txt2speech(story) # Converts the story to audio
|
105 |
-
|
106 |
-
st.markdown("---")
|
107 |
-
st.markdown("## π Image Caption")
|
108 |
-
st.write(scenario)
|
109 |
-
|
110 |
-
st.markdown("---")
|
111 |
-
st.markdown("## π Story")
|
112 |
-
st.write(story)
|
113 |
-
|
114 |
-
st.markdown("---")
|
115 |
-
st.markdown("## π§ Audio Story")
|
116 |
-
st.audio("audio_story.mp3")
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
|
122 |
-
|
123 |
-
|
124 |
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
if __name__ == '__main__':
|
134 |
main()
|
|
|
80 |
|
81 |
st.sidebar.title("Choose the task")
|
82 |
|
83 |
+
# Function for the Audio Story page
|
84 |
+
def audio_story_page():
|
85 |
+
st.title("π¨ Image-to-Audio Story π§")
|
86 |
+
st.write("Turn the Image into Audio Story")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
+
uploaded_file = st.file_uploader("Upload an image...", type=["jpg", "jpeg", "png"])
|
89 |
+
|
90 |
+
if uploaded_file is not None:
|
91 |
+
bytes_data = uploaded_file.read()
|
92 |
+
with open("uploaded_image.jpg", "wb") as file:
|
93 |
+
file.write(bytes_data)
|
94 |
+
|
95 |
+
st.image(uploaded_file, caption='πΌοΈ Uploaded Image', use_column_width=True)
|
96 |
+
|
97 |
+
with st.spinner("AI is at Work!"):
|
98 |
+
scenario = img2txt("uploaded_image.jpg")
|
99 |
+
story = generate_story(scenario, llm)
|
100 |
+
txt2speech(story)
|
101 |
+
|
102 |
+
st.markdown("---")
|
103 |
+
st.markdown("## π Image Caption")
|
104 |
+
st.write(scenario)
|
105 |
+
|
106 |
+
st.markdown("---")
|
107 |
+
st.markdown("## π Story")
|
108 |
+
st.write(story)
|
109 |
+
|
110 |
+
st.markdown("---")
|
111 |
+
st.markdown("## π§ Audio Story")
|
112 |
+
st.audio("audio_story.mp3")
|
113 |
+
|
114 |
+
# Function for the Image Generator page
|
115 |
+
def image_generator_page():
|
116 |
+
st.title("Stable Diffusion Image Generation")
|
117 |
+
st.write("This app lets you generate images using Stable Diffusion with the Euler scheduler.")
|
118 |
|
119 |
+
prompt = st.text_input("Enter your prompt:")
|
120 |
+
image_style = st.selectbox("Style Selection", ["realistic", "cartoon", "watercolor"])
|
121 |
|
122 |
+
if st.button("Generate Image"):
|
123 |
+
if prompt:
|
124 |
+
with st.spinner("Generating image..."):
|
125 |
+
image = txt2img(prompt=prompt, style=image_style)
|
126 |
+
st.image(image)
|
127 |
+
else:
|
128 |
+
st.error("Please enter a prompt.")
|
129 |
+
|
130 |
+
# Function for the Home page
|
131 |
+
def home_page():
|
132 |
+
st.title("Welcome to your Creative Canvas!")
|
133 |
+
st.write("Use the tools in the sidebar to create audio stories and unique images.")
|
134 |
+
|
135 |
+
# Streamlit web app main function
|
136 |
+
def main():
|
137 |
+
selection = st.sidebar.radio("Go to", ["Home", "Audio Story", "Image Generator"])
|
138 |
+
|
139 |
+
if selection == "Home":
|
140 |
+
home_page()
|
141 |
+
elif selection == "Audio Story":
|
142 |
+
audio_story_page()
|
143 |
+
elif selection == "Image Generator":
|
144 |
+
image_generator_page()
|
145 |
|
146 |
if __name__ == '__main__':
|
147 |
main()
|