codewithdark commited on
Commit
bef91cd
1 Parent(s): 83804c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -61
app.py CHANGED
@@ -1,61 +1,61 @@
1
- import streamlit as st
2
- import os
3
- import asyncio
4
- from dotenv import load_dotenv
5
- from utility.logging import log_response
6
- from utility.script_generator import generate_script
7
- from utility.audio_generator import generate_audio
8
- from utility.timed_captions_generator import generate_timed_captions
9
- from utility.image_generator import generate_image_prompts, generate_images
10
- from utility.render_engine import get_output_media
11
-
12
- # Load environment variables
13
- load_dotenv()
14
-
15
- # Define async function to run in Streamlit
16
- async def generate_content(topic):
17
- st.write("Generating script for topic:", topic)
18
- script = generate_script(topic)
19
- st.write("Generated Script:")
20
- st.write(script)
21
-
22
- audio_file = "output_audio.mp3"
23
-
24
- st.write("Generating audio...")
25
- await generate_audio(script, audio_file)
26
- st.write(f"Audio generated and saved to {audio_file}")
27
-
28
- st.write("Generating timed captions...")
29
- captions_timed = generate_timed_captions(audio_file)
30
- st.write("Timed Captions:")
31
- st.write(captions_timed)
32
-
33
- st.write("Generating images from prompts...")
34
- prompts = generate_image_prompts(script)
35
- image_files = generate_images(prompts)
36
- st.write("Generated Images:")
37
- st.image(image_files, caption=prompts, use_column_width=True)
38
-
39
- st.write("Rendering output media...")
40
- output_file = get_output_media(audio_file, captions_timed, image_files)
41
- st.write(f"Output media generated: {output_file}")
42
-
43
- # Provide a link to download the output video file
44
- with open(output_file, 'rb') as f:
45
- st.download_button(label="Download Output Video", data=f, file_name=output_file, mime='video/mp4')
46
-
47
- # Define the Streamlit app layout
48
- def main():
49
- st.title("AI Media Content Generator")
50
- st.write("This app generates audio, images, and captions based on a topic using AI.")
51
-
52
- # Input field for the topic
53
- topic = st.text_input("Enter a topic:", "Future of AI")
54
-
55
- # Run the generation when button is clicked
56
- if st.button("Generate Content"):
57
- # Run the asynchronous function using asyncio and Streamlit's `st.experimental_singleton` to handle async calls
58
- asyncio.run(generate_content(topic))
59
-
60
- if __name__ == "__main__":
61
- main()
 
1
+ import gradio as gr
2
+ import os
3
+ import asyncio
4
+ from dotenv import load_dotenv
5
+ from utility.logging import log_response
6
+ from utility.script_generator import generate_script
7
+ from utility.audio_generator import generate_audio
8
+ from utility.timed_captions_generator import generate_timed_captions
9
+ from utility.image_generator import generate_image_prompts, generate_images
10
+ from utility.render_engine import get_output_media
11
+
12
+ # Load environment variables
13
+ load_dotenv()
14
+
15
+ # Async function to generate content
16
+ async def generate_content_gradio(topic):
17
+ script = generate_script(topic)
18
+
19
+ audio_file = "output_audio.mp3"
20
+ await generate_audio(script, audio_file)
21
+
22
+ captions_timed = generate_timed_captions(audio_file)
23
+
24
+ prompts = generate_image_prompts(script)
25
+ image_files = generate_images(prompts)
26
+
27
+ output_file = get_output_media(audio_file, captions_timed, image_files)
28
+
29
+ return script, audio_file, image_files, output_file
30
+
31
+ # Gradio interface function
32
+ async def generate_content_interface(topic):
33
+ script, audio_file, image_files, output_file = await generate_content_gradio(topic)
34
+
35
+ # For Gradio outputs: Text for script, audio file, image(s), and output media file
36
+ return script, audio_file, image_files, output_file
37
+
38
+ # Define Gradio app layout
39
+ def main():
40
+ # Gradio Interface
41
+ with gr.Blocks() as demo:
42
+ gr.Markdown("# AI Media Content Generator")
43
+ gr.Markdown("This app generates audio, images, and captions based on a topic using AI.")
44
+
45
+ # Input field for the topic
46
+ topic_input = gr.Textbox(label="Enter a topic", placeholder="Future of AI")
47
+
48
+ # Outputs: Script (Text), Audio (Audio), Images (Image List), Final Media (Video)
49
+ script_output = gr.Textbox(label="Generated Script")
50
+ audio_output = gr.Audio(label="Generated Audio")
51
+ images_output = gr.Gallery(label="Generated Images")
52
+ output_media = gr.Video(label="Output Media")
53
+
54
+ # Define the event when clicking the button
55
+ generate_btn = gr.Button("Generate Content")
56
+ generate_btn.click(fn=generate_content_interface, inputs=topic_input, outputs=[script_output, audio_output, images_output, output_media])
57
+
58
+ return demo
59
+
60
+ if __name__ == "__main__":
61
+ main().launch()