Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,7 @@ from moviepy.editor import VideoFileClip
|
|
| 6 |
from datetime import datetime
|
| 7 |
import pytz
|
| 8 |
from audio_recorder_streamlit import audio_recorder
|
|
|
|
| 9 |
|
| 10 |
openai.api_key, openai.organization = os.getenv('OPENAI_API_KEY'), os.getenv('OPENAI_ORG_ID')
|
| 11 |
client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'), organization=os.getenv('OPENAI_ORG_ID'))
|
|
@@ -102,12 +103,12 @@ def process_audio_for_video(video_input):
|
|
| 102 |
if video_input:
|
| 103 |
st.session_state.messages.append({"role": "user", "content": video_input})
|
| 104 |
transcription = client.audio.transcriptions.create(model="whisper-1", file=video_input)
|
| 105 |
-
response = client.chat.completions.create(model=MODEL, messages=[{"role": "system", "content":"You are generating a transcript summary. Create a summary of the provided transcription. Respond in Markdown."}, {"role": "user", "content": [{"type": "text", "text": f"The audio transcription is: {transcription}"}]}], temperature=0)
|
| 106 |
video_response = response.choices[0].message.content
|
| 107 |
with st.chat_message("assistant"):
|
| 108 |
st.markdown(video_response)
|
| 109 |
-
filename = generate_filename(transcription, "md")
|
| 110 |
-
create_file(filename, transcription, video_response, should_save=True)
|
| 111 |
st.session_state.messages.append({"role": "assistant", "content": video_response})
|
| 112 |
return video_response
|
| 113 |
|
|
@@ -147,6 +148,39 @@ def save_and_play_audio(audio_recorder):
|
|
| 147 |
return filename
|
| 148 |
return None
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
def main():
|
| 151 |
st.markdown("##### GPT-4o Omni Model: Text, Audio, Image, & Video")
|
| 152 |
option = st.selectbox("Select an option", ("Text", "Image", "Audio", "Video"))
|
|
@@ -192,5 +226,12 @@ def main():
|
|
| 192 |
response = process_text2(text_input=prompt)
|
| 193 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
if __name__ == "__main__":
|
| 196 |
main()
|
|
|
|
| 6 |
from datetime import datetime
|
| 7 |
import pytz
|
| 8 |
from audio_recorder_streamlit import audio_recorder
|
| 9 |
+
from PIL import Image
|
| 10 |
|
| 11 |
openai.api_key, openai.organization = os.getenv('OPENAI_API_KEY'), os.getenv('OPENAI_ORG_ID')
|
| 12 |
client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'), organization=os.getenv('OPENAI_ORG_ID'))
|
|
|
|
| 103 |
if video_input:
|
| 104 |
st.session_state.messages.append({"role": "user", "content": video_input})
|
| 105 |
transcription = client.audio.transcriptions.create(model="whisper-1", file=video_input)
|
| 106 |
+
response = client.chat.completions.create(model=MODEL, messages=[{"role": "system", "content":"You are generating a transcript summary. Create a summary of the provided transcription. Respond in Markdown."}, {"role": "user", "content": [{"type": "text", "text": f"The audio transcription is: {transcription.text}"}]}], temperature=0)
|
| 107 |
video_response = response.choices[0].message.content
|
| 108 |
with st.chat_message("assistant"):
|
| 109 |
st.markdown(video_response)
|
| 110 |
+
filename = generate_filename(transcription.text, "md")
|
| 111 |
+
create_file(filename, transcription.text, video_response, should_save=True)
|
| 112 |
st.session_state.messages.append({"role": "assistant", "content": video_response})
|
| 113 |
return video_response
|
| 114 |
|
|
|
|
| 148 |
return filename
|
| 149 |
return None
|
| 150 |
|
| 151 |
+
@st.cache_resource
|
| 152 |
+
def display_videos_and_links(num_columns):
|
| 153 |
+
video_files = [f for f in os.listdir('.') if f.endswith('.mp4')]
|
| 154 |
+
if not video_files:
|
| 155 |
+
st.write("No MP4 videos found in the current directory.")
|
| 156 |
+
return
|
| 157 |
+
video_files_sorted = sorted(video_files, key=lambda x: len(x.split('.')[0]))
|
| 158 |
+
cols = st.columns(num_columns) # Define num_columns columns outside the loop
|
| 159 |
+
col_index = 0 # Initialize column index
|
| 160 |
+
for video_file in video_files_sorted:
|
| 161 |
+
with cols[col_index % num_columns]: # Use modulo 2 to alternate between the first and second column
|
| 162 |
+
k = video_file.split('.')[0] # Assumes keyword is the file name without extension
|
| 163 |
+
st.video(video_file, format='video/mp4', start_time=0)
|
| 164 |
+
display_glossary_entity(k)
|
| 165 |
+
col_index += 1 # Increment column index to place the next video in the next column
|
| 166 |
+
|
| 167 |
+
@st.cache_resource
|
| 168 |
+
def display_images_and_wikipedia_summaries(num_columns=4):
|
| 169 |
+
image_files = [f for f in os.listdir('.') if f.endswith('.png')]
|
| 170 |
+
if not image_files:
|
| 171 |
+
st.write("No PNG images found in the current directory.")
|
| 172 |
+
return
|
| 173 |
+
image_files_sorted = sorted(image_files, key=lambda x: len(x.split('.')[0]))
|
| 174 |
+
cols = st.columns(num_columns) # Use specified num_columns for layout
|
| 175 |
+
col_index = 0 # Initialize column index for cycling through columns
|
| 176 |
+
for image_file in image_files_sorted:
|
| 177 |
+
with cols[col_index % num_columns]: # Cycle through columns based on num_columns
|
| 178 |
+
image = Image.open(image_file)
|
| 179 |
+
st.image(image, caption=image_file, use_column_width=True)
|
| 180 |
+
k = image_file.split('.')[0] # Assumes keyword is the file name without extension
|
| 181 |
+
display_glossary_entity(k)
|
| 182 |
+
col_index += 1 # Increment to move to the next column in the next iteration
|
| 183 |
+
|
| 184 |
def main():
|
| 185 |
st.markdown("##### GPT-4o Omni Model: Text, Audio, Image, & Video")
|
| 186 |
option = st.selectbox("Select an option", ("Text", "Image", "Audio", "Video"))
|
|
|
|
| 226 |
response = process_text2(text_input=prompt)
|
| 227 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 228 |
|
| 229 |
+
# Image and Video Galleries
|
| 230 |
+
num_columns_images=st.slider(key="num_columns_images", label="Choose Number of Image Columns", min_value=1, max_value=15, value=5)
|
| 231 |
+
display_images_and_wikipedia_summaries(num_columns_images) # Image Jump Grid
|
| 232 |
+
|
| 233 |
+
num_columns_video=st.slider(key="num_columns_video", label="Choose Number of Video Columns", min_value=1, max_value=15, value=5)
|
| 234 |
+
display_videos_and_links(num_columns_video) # Video Jump Grid
|
| 235 |
+
|
| 236 |
if __name__ == "__main__":
|
| 237 |
main()
|