-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfinal_page.py
67 lines (49 loc) · 1.98 KB
/
final_page.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
61
62
63
64
65
66
67
from mistralai import SystemMessage, UserMessage
import streamlit as st
from markdown_formatter import markdown_insert_images
#import luma_generate
import shutil
import os
def final_page(client):
with open(f"stories/{st.session_state.session_id}/story.md", "r") as story_file:
story = story_file.read()
story = markdown_insert_images(story, session_id=st.session_state.session_id)
with st.container():
st.markdown(story, unsafe_allow_html=True)
story_dir = f"./stories/{st.session_state.session_id}"
story_path = f"{story_dir}_story"
story_zip = f"{story_dir}_story.zip"
if not st.session_state.saved:
if not os.path.exists(story_zip):
# os.makedirs(story_dir)
shutil.make_archive(story_path, "zip", story_dir)
st.session_state.saved = True
with open(story_zip, "rb") as fp:
download_button = st.download_button(
label="Download story", data=fp, file_name=story_zip, mime="application/zip"
)
"""
generate_video = st.button(label="Generate video")
if generate_video:
with open(f"stories/{st.session_state.session_id}/story.md", "r") as story_file:
story = story_file.read()
story_response = client.chat.complete(
model=st.session_state["mistral_model"],
messages=[
UserMessage(
role="user",
content="Create a prompt to generate a 5 second video of this story. It should be less than 50 words"
+ story,
),
],
)
video_prompt = story_response.choices[0].message.content
print(video_prompt)
video_path = luma_generate.generate_video(
st.session_state.session_id, prompt=video_prompt
)
st.session_state.video_path = video_path
st.session_state.video_generated = True
if "video_generated" in st.session_state:
st.video(st.session_state.video_path)
"""