Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,18 +20,16 @@ def load_model():
|
|
| 20 |
|
| 21 |
# Step 2: Upload image or video
|
| 22 |
def upload_media():
|
| 23 |
-
st.write("Step 2: Upload an image or video")
|
| 24 |
return st.file_uploader("Choose images or videos...", type=["jpg", "jpeg", "png", "mp4", "avi", "mov"], accept_multiple_files=True)
|
| 25 |
|
| 26 |
# Step 3: Enter your question
|
| 27 |
def get_user_question():
|
| 28 |
-
st.write("Step 3: Enter your question")
|
| 29 |
return st.text_input("Ask a question about the images or videos:")
|
| 30 |
|
| 31 |
# Process image
|
| 32 |
def process_image(uploaded_file):
|
| 33 |
image = Image.open(uploaded_file)
|
| 34 |
-
image = image.resize((
|
| 35 |
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 36 |
return image
|
| 37 |
|
|
@@ -82,7 +80,8 @@ def generate_story(descriptions):
|
|
| 82 |
|
| 83 |
# Main function to control the flow
|
| 84 |
def main():
|
| 85 |
-
st.title("Media
|
|
|
|
| 86 |
|
| 87 |
# Step 1: Load the model
|
| 88 |
processor, model, device = load_model()
|
|
@@ -100,7 +99,6 @@ def main():
|
|
| 100 |
generate_description_button = st.button("Generate Description")
|
| 101 |
|
| 102 |
if generate_description_button:
|
| 103 |
-
all_output_texts = []
|
| 104 |
|
| 105 |
for uploaded_file in uploaded_files:
|
| 106 |
file_type = uploaded_file.type.split('/')[0]
|
|
@@ -125,15 +123,14 @@ def main():
|
|
| 125 |
torch.cuda.empty_cache()
|
| 126 |
torch.manual_seed(0)
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
generate_story_button = st.button("Generate Story")
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
|
| 138 |
if __name__ == "__main__":
|
| 139 |
main()
|
|
|
|
| 20 |
|
| 21 |
# Step 2: Upload image or video
|
| 22 |
def upload_media():
|
|
|
|
| 23 |
return st.file_uploader("Choose images or videos...", type=["jpg", "jpeg", "png", "mp4", "avi", "mov"], accept_multiple_files=True)
|
| 24 |
|
| 25 |
# Step 3: Enter your question
|
| 26 |
def get_user_question():
|
|
|
|
| 27 |
return st.text_input("Ask a question about the images or videos:")
|
| 28 |
|
| 29 |
# Process image
|
| 30 |
def process_image(uploaded_file):
|
| 31 |
image = Image.open(uploaded_file)
|
| 32 |
+
image = image.resize((512, 512)) # Reduce size to save memory
|
| 33 |
st.image(image, caption='Uploaded Image.', use_column_width=True)
|
| 34 |
return image
|
| 35 |
|
|
|
|
| 80 |
|
| 81 |
# Main function to control the flow
|
| 82 |
def main():
|
| 83 |
+
st.title("Media Story Generator")
|
| 84 |
+
all_output_texts = []
|
| 85 |
|
| 86 |
# Step 1: Load the model
|
| 87 |
processor, model, device = load_model()
|
|
|
|
| 99 |
generate_description_button = st.button("Generate Description")
|
| 100 |
|
| 101 |
if generate_description_button:
|
|
|
|
| 102 |
|
| 103 |
for uploaded_file in uploaded_files:
|
| 104 |
file_type = uploaded_file.type.split('/')[0]
|
|
|
|
| 123 |
torch.cuda.empty_cache()
|
| 124 |
torch.manual_seed(0)
|
| 125 |
|
| 126 |
+
if all_output_texts:
|
| 127 |
+
# Step 5: Generate story
|
| 128 |
+
generate_story_button = st.button("Generate Story")
|
|
|
|
| 129 |
|
| 130 |
+
if generate_story_button:
|
| 131 |
+
story = generate_story(all_output_texts)
|
| 132 |
+
st.write("Generated Story:")
|
| 133 |
+
st.write(story)
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|
| 136 |
main()
|