updates
Browse files1. Updated 'generate_images()' to stream(yield) an image as soon as it is generated
2. Transcription -> prompts( if audio in 'Already in English')
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import io
|
|
| 4 |
from gradio_client import Client, handle_file
|
| 5 |
import tempfile
|
| 6 |
import os
|
| 7 |
-
from utils import clean_response, get_translation, get_image_prompts, generate_images, generate_video
|
| 8 |
import constants
|
| 9 |
|
| 10 |
# Initialize the client only once
|
|
@@ -123,25 +123,36 @@ if audio_file:
|
|
| 123 |
# Image prompts - generated once translation is available
|
| 124 |
if st.session_state.translation:
|
| 125 |
st.write("### Image Prompts")
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
else:
|
| 145 |
# If no file is uploaded yet
|
| 146 |
st.warning("Please upload an audio file to proceed.")
|
| 147 |
-
|
|
|
|
| 4 |
from gradio_client import Client, handle_file
|
| 5 |
import tempfile
|
| 6 |
import os
|
| 7 |
+
from utils import clean_response, get_translation, get_image_prompts, generate_images, generate_video
|
| 8 |
import constants
|
| 9 |
|
| 10 |
# Initialize the client only once
|
|
|
|
| 123 |
# Image prompts - generated once translation is available
|
| 124 |
if st.session_state.translation:
|
| 125 |
st.write("### Image Prompts")
|
| 126 |
+
|
| 127 |
+
# Determine whether to use translation or transcription for image generation
|
| 128 |
+
prompts = []
|
| 129 |
+
if 'Already in English' in st.session_state.translation:
|
| 130 |
+
st.info("Audio is Already in English. Using Transcription to generate Image Prompts")
|
| 131 |
+
prompts = get_image_prompts(st.session_state.transcript)['image_prompts']
|
| 132 |
+
else:
|
| 133 |
+
prompts = get_image_prompts(st.session_state.translation)['image_prompts']
|
| 134 |
+
|
| 135 |
+
# Display the prompts
|
| 136 |
+
for i, prompt in enumerate(prompts):
|
| 137 |
+
st.write(f"**Prompt {i+1}:** {prompt}")
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
# Generate and display images using the generator
|
| 141 |
+
for prompt, image_path in generate_images(prompts):
|
| 142 |
+
st.image(image_path, caption=f"Prompt: {prompt}", use_column_width=True)
|
| 143 |
+
st.write(f"Generated from: {prompt}")
|
| 144 |
+
|
| 145 |
+
st.info("Video Generation Feature Currently Under Development")
|
| 146 |
+
# # Generate the video based on the images and translation
|
| 147 |
+
# st.write("### Generating Video...")
|
| 148 |
+
# with st.spinner("Creating video..."):
|
| 149 |
+
# video_file = generate_video(images_folder, st.session_state.translation)
|
| 150 |
+
# if video_file:
|
| 151 |
+
# st.session_state.generated_video = video_file
|
| 152 |
+
# st.video(video_file) # Display the video
|
| 153 |
+
# else:
|
| 154 |
+
# st.error("Failed to generate the video.")
|
| 155 |
|
| 156 |
else:
|
| 157 |
# If no file is uploaded yet
|
| 158 |
st.warning("Please upload an audio file to proceed.")
|
|
|
utils.py
CHANGED
|
@@ -97,8 +97,8 @@ def generate_images(image_prompts, folder_name='test_folder'):
|
|
| 97 |
folder_path = tmp_folder(folder_name)
|
| 98 |
for index, prompt in enumerate(image_prompts):
|
| 99 |
print(index, prompt)
|
| 100 |
-
generate_image(prompt=prompt, path=f"{folder_path}/{index}.png")
|
| 101 |
-
|
| 102 |
|
| 103 |
|
| 104 |
|
|
|
|
| 97 |
folder_path = tmp_folder(folder_name)
|
| 98 |
for index, prompt in enumerate(image_prompts):
|
| 99 |
print(index, prompt)
|
| 100 |
+
image_path = generate_image(prompt=prompt, path=f"{folder_path}/{index}.png")
|
| 101 |
+
yield prompt, image_path
|
| 102 |
|
| 103 |
|
| 104 |
|