matejmicek commited on
Commit
a629947
1 Parent(s): 6a2cddd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -3
app.py CHANGED
@@ -61,7 +61,7 @@ def analyze_image(base64_image):
61
  },
62
  ]
63
  + generate_new_line(base64_image),
64
- max_tokens=500,
65
  )
66
  response_text = response.choices[0].message.content
67
  return response_text
@@ -82,8 +82,22 @@ def save_uploaded_file(uploaded_file):
82
 
83
  return os.path.join(save_path, 'temp')
84
 
85
- def process():
86
- pass # Assuming 'process' is defined in 'your_processing_module'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
  def main():
89
  st.title("Image to Audio Converter")
@@ -103,6 +117,30 @@ def main():
103
  if audio_file is not None:
104
  st.audio(audio_file, format='audio/mp3')
105
  st.download_button('Download Audio', audio_file, file_name='narrated.mp3')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
  if __name__ == "__main__":
108
  main()
 
61
  },
62
  ]
63
  + generate_new_line(base64_image),
64
+ max_tokens=100,
65
  )
66
  response_text = response.choices[0].message.content
67
  return response_text
 
82
 
83
  return os.path.join(save_path, 'temp')
84
 
85
+
86
+ def save_audio_file(audio):
87
+ # Create a directory to save the file
88
+ save_path = 'audio'
89
+ if not os.path.exists(save_path):
90
+ os.makedirs(save_path)
91
+
92
+ # Save the file
93
+ with open(os.path.join(save_path, 'temp.mp3'), "wb") as f:
94
+ f.write(audio)
95
+
96
+ return os.path.join(save_path, 'temp')
97
+
98
+
99
+ from moviepy.editor import ImageClip, AudioFileClip
100
+
101
 
102
  def main():
103
  st.title("Image to Audio Converter")
 
117
  if audio_file is not None:
118
  st.audio(audio_file, format='audio/mp3')
119
  st.download_button('Download Audio', audio_file, file_name='narrated.mp3')
120
+ audio_filename = 'narrated.mp3'
121
+ with open(audio_filename, 'wb') as f:
122
+ f.write(audio_file)
123
+
124
+ print('creating video')
125
+ # Create a video clip from the static image
126
+ video_clip = ImageClip(path).set_duration(AudioFileClip(audio_filename).duration)
127
+
128
+
129
+ # Set the audio of the video clip as the generated audio file
130
+ video_clip = video_clip.set_audio(AudioFileClip(audio_filename))
131
+
132
+ print('video created')
133
+
134
+ # Specify the filename for the video
135
+ video_filename = "narrated_video.mp4"
136
+
137
+ # Write the video file to disk
138
+ video_clip.write_videofile(video_filename, codec="libx264", audio_codec="aac", fps=24)
139
+
140
+ # Provide a download button for the video
141
+ with open(video_filename, "rb") as file:
142
+ st.video(video_filename)
143
+ st.download_button('Download Video', file, file_name=video_filename)
144
 
145
  if __name__ == "__main__":
146
  main()