trying
Browse files
app.py
CHANGED
|
@@ -41,28 +41,40 @@ def video_to_frames(video_file):
|
|
| 41 |
return base64Frames, video_filename, video_duration
|
| 42 |
|
| 43 |
|
| 44 |
-
def frames_to_story(
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
params = {
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
"headers": {"Openai-Version": "2020-11-07"},
|
| 60 |
-
"max_tokens": 500,
|
| 61 |
}
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
def text_to_audio(text):
|
|
|
|
| 41 |
return base64Frames, video_filename, video_duration
|
| 42 |
|
| 43 |
|
| 44 |
+
def frames_to_story(frames, prompt):
|
| 45 |
+
|
| 46 |
+
try:
|
| 47 |
+
# Format prompt with Markdown
|
| 48 |
+
prompt = f"**Summary:** {prompt}"
|
| 49 |
+
|
| 50 |
+
messages = [{
|
| 51 |
+
"role": "user",
|
| 52 |
+
"content": [prompt, *frames]
|
| 53 |
+
}]
|
| 54 |
+
|
| 55 |
params = {
|
| 56 |
+
"model": "gpt-3.5-turbo",
|
| 57 |
+
"messages": messages,
|
| 58 |
+
"max_tokens": 100,
|
|
|
|
|
|
|
| 59 |
}
|
| 60 |
|
| 61 |
+
response = openai.Chat.create(**params)
|
| 62 |
+
|
| 63 |
+
story = response.choices[0].message.content
|
| 64 |
+
|
| 65 |
+
# Generate audio stream from text
|
| 66 |
+
audio_bytes = text_to_audio(story)
|
| 67 |
+
|
| 68 |
+
# Display word count
|
| 69 |
+
word_count = len(story.split())
|
| 70 |
+
st.write(f"**Words:** {word_count}")
|
| 71 |
+
|
| 72 |
+
return story, audio_bytes
|
| 73 |
+
|
| 74 |
+
except Exception as e:
|
| 75 |
+
st.error("Error generating story:", e)
|
| 76 |
+
return None, None
|
| 77 |
+
|
| 78 |
|
| 79 |
|
| 80 |
def text_to_audio(text):
|