Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,61 +1,61 @@
|
|
| 1 |
-
import
|
| 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 |
-
#
|
| 16 |
-
async def
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 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()
|