yuvaranianandhan24 commited on
Commit
54751e4
Β·
verified Β·
1 Parent(s): 7915f9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -46
app.py CHANGED
@@ -80,55 +80,68 @@ def txt2img(text, style="realistic"):
80
 
81
  st.sidebar.title("Choose the task")
82
 
83
- # Streamlit web app main function
84
- def main():
85
- st.title("Welcome to your Creative Canvas!")
86
- st.write("Use the tools in the sidebar to create audio stories and unique images.")
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
- with st.expander("Image Generator"):
119
- st.title("Stable Diffusion Image Generation")
120
- st.write("This app lets you generate images using Stable Diffusion with the Euler scheduler.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
- prompt = st.text_input("Enter your prompt:")
123
- image_style = st.selectbox("Style Selection", ["realistic", "cartoon", "watercolor"])
124
 
125
- if st.button("Generate Image"):
126
- if prompt:
127
- with st.spinner("Generating image..."):
128
- image = txt2img(prompt=prompt, style=image_style)
129
- st.image(image)
130
- else:
131
- st.error("Please enter a prompt.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()