Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -247,9 +247,141 @@ def generate_filename(prompt, file_type):
|
|
| 247 |
safe_prompt = re.sub(r'\s+', ' ', replaced_prompt).strip()[:230]
|
| 248 |
return f"{safe_date_time}_{safe_prompt}.{file_type}"
|
| 249 |
|
| 250 |
-
#
|
| 251 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
def main():
|
| 254 |
st.sidebar.markdown("### π²BikeAIπ Claude and GPT Multi-Agent Research AI")
|
| 255 |
|
|
|
|
| 247 |
safe_prompt = re.sub(r'\s+', ' ', replaced_prompt).strip()[:230]
|
| 248 |
return f"{safe_date_time}_{safe_prompt}.{file_type}"
|
| 249 |
|
| 250 |
+
# File Management Functions
|
| 251 |
+
def load_file(file_name):
|
| 252 |
+
"""Load file content."""
|
| 253 |
+
with open(file_name, "r", encoding='utf-8') as file:
|
| 254 |
+
content = file.read()
|
| 255 |
+
return content
|
| 256 |
|
| 257 |
+
def create_zip_of_files(files):
|
| 258 |
+
"""Create zip archive of files."""
|
| 259 |
+
zip_name = "all_files.zip"
|
| 260 |
+
with zipfile.ZipFile(zip_name, 'w') as zipf:
|
| 261 |
+
for file in files:
|
| 262 |
+
zipf.write(file)
|
| 263 |
+
return zip_name
|
| 264 |
+
|
| 265 |
+
def get_download_link(file):
|
| 266 |
+
"""Create download link for file."""
|
| 267 |
+
with open(file, "rb") as f:
|
| 268 |
+
contents = f.read()
|
| 269 |
+
b64 = base64.b64encode(contents).decode()
|
| 270 |
+
return f'<a href="data:file/txt;base64,{b64}" download="{os.path.basename(file)}">Download {os.path.basename(file)}π</a>'
|
| 271 |
+
|
| 272 |
+
def display_file_manager():
|
| 273 |
+
"""Display file management sidebar."""
|
| 274 |
+
st.sidebar.title("π File Management")
|
| 275 |
+
|
| 276 |
+
all_files = glob.glob("*.md")
|
| 277 |
+
all_files.sort(reverse=True)
|
| 278 |
+
|
| 279 |
+
if st.sidebar.button("π Delete All"):
|
| 280 |
+
for file in all_files:
|
| 281 |
+
os.remove(file)
|
| 282 |
+
st.rerun()
|
| 283 |
+
|
| 284 |
+
if st.sidebar.button("β¬οΈ Download All"):
|
| 285 |
+
zip_file = create_zip_of_files(all_files)
|
| 286 |
+
st.sidebar.markdown(get_download_link(zip_file), unsafe_allow_html=True)
|
| 287 |
+
|
| 288 |
+
for file in all_files:
|
| 289 |
+
col1, col2, col3, col4 = st.sidebar.columns([1,3,1,1])
|
| 290 |
+
with col1:
|
| 291 |
+
if st.button("π", key="view_"+file):
|
| 292 |
+
st.session_state.current_file = file
|
| 293 |
+
st.session_state.file_content = load_file(file)
|
| 294 |
+
with col2:
|
| 295 |
+
st.markdown(get_download_link(file), unsafe_allow_html=True)
|
| 296 |
+
with col3:
|
| 297 |
+
if st.button("π", key="edit_"+file):
|
| 298 |
+
st.session_state.current_file = file
|
| 299 |
+
st.session_state.file_content = load_file(file)
|
| 300 |
+
with col4:
|
| 301 |
+
if st.button("π", key="delete_"+file):
|
| 302 |
+
os.remove(file)
|
| 303 |
+
st.rerun()
|
| 304 |
+
|
| 305 |
+
def create_media_gallery():
|
| 306 |
+
"""Create the media gallery interface."""
|
| 307 |
+
st.header("π¬ Media Gallery")
|
| 308 |
+
|
| 309 |
+
tabs = st.tabs(["πΌοΈ Images", "π΅ Audio", "π₯ Video", "π¨ Scene Generator"])
|
| 310 |
+
|
| 311 |
+
with tabs[0]:
|
| 312 |
+
image_files = glob.glob("*.png") + glob.glob("*.jpg")
|
| 313 |
+
if image_files:
|
| 314 |
+
num_cols = st.slider("Number of columns", 1, 5, 3)
|
| 315 |
+
cols = st.columns(num_cols)
|
| 316 |
+
for idx, image_file in enumerate(image_files):
|
| 317 |
+
with cols[idx % num_cols]:
|
| 318 |
+
img = Image.open(image_file)
|
| 319 |
+
st.image(img, use_container_width=True)
|
| 320 |
+
|
| 321 |
+
# Add GPT vision analysis option
|
| 322 |
+
if st.button(f"Analyze {os.path.basename(image_file)}"):
|
| 323 |
+
analysis = process_image(image_file,
|
| 324 |
+
"Describe this image in detail and identify key elements.")
|
| 325 |
+
st.markdown(analysis)
|
| 326 |
+
|
| 327 |
+
with tabs[1]:
|
| 328 |
+
audio_files = glob.glob("*.mp3") + glob.glob("*.wav")
|
| 329 |
+
for audio_file in audio_files:
|
| 330 |
+
with st.expander(f"π΅ {os.path.basename(audio_file)}"):
|
| 331 |
+
st.markdown(get_media_html(audio_file, "audio"), unsafe_allow_html=True)
|
| 332 |
+
if st.button(f"Transcribe {os.path.basename(audio_file)}"):
|
| 333 |
+
with open(audio_file, "rb") as f:
|
| 334 |
+
transcription = process_audio(f)
|
| 335 |
+
st.write(transcription)
|
| 336 |
+
|
| 337 |
+
with tabs[2]:
|
| 338 |
+
video_files = glob.glob("*.mp4")
|
| 339 |
+
for video_file in video_files:
|
| 340 |
+
with st.expander(f"π₯ {os.path.basename(video_file)}"):
|
| 341 |
+
st.markdown(get_media_html(video_file, "video"), unsafe_allow_html=True)
|
| 342 |
+
if st.button(f"Analyze {os.path.basename(video_file)}"):
|
| 343 |
+
analysis = process_video_with_gpt(video_file,
|
| 344 |
+
"Describe what's happening in this video.")
|
| 345 |
+
st.markdown(analysis)
|
| 346 |
+
|
| 347 |
+
with tabs[3]:
|
| 348 |
+
for collection_name, bikes in bike_collections.items():
|
| 349 |
+
st.subheader(collection_name)
|
| 350 |
+
cols = st.columns(len(bikes))
|
| 351 |
+
|
| 352 |
+
for idx, (bike_name, details) in enumerate(bikes.items()):
|
| 353 |
+
with cols[idx]:
|
| 354 |
+
st.markdown(f"""
|
| 355 |
+
<div class='bike-card'>
|
| 356 |
+
<h3>{details['emoji']} {bike_name}</h3>
|
| 357 |
+
<p>{details['prompt']}</p>
|
| 358 |
+
</div>
|
| 359 |
+
""", unsafe_allow_html=True)
|
| 360 |
+
|
| 361 |
+
if st.button(f"Generate {bike_name} Scene"):
|
| 362 |
+
prompt = details['prompt']
|
| 363 |
+
# Here you could integrate with image generation API
|
| 364 |
+
st.write(f"Generated scene description for {bike_name}:")
|
| 365 |
+
st.write(prompt)
|
| 366 |
+
|
| 367 |
+
def get_media_html(media_path, media_type="video", width="100%"):
|
| 368 |
+
"""Generate HTML for media player."""
|
| 369 |
+
media_data = base64.b64encode(open(media_path, 'rb').read()).decode()
|
| 370 |
+
if media_type == "video":
|
| 371 |
+
return f'''
|
| 372 |
+
<video width="{width}" controls autoplay muted loop>
|
| 373 |
+
<source src="data:video/mp4;base64,{media_data}" type="video/mp4">
|
| 374 |
+
Your browser does not support the video tag.
|
| 375 |
+
</video>
|
| 376 |
+
'''
|
| 377 |
+
else: # audio
|
| 378 |
+
return f'''
|
| 379 |
+
<audio controls style="width: {width};">
|
| 380 |
+
<source src="data:audio/mpeg;base64,{media_data}" type="audio/mpeg">
|
| 381 |
+
Your browser does not support the audio element.
|
| 382 |
+
</audio>
|
| 383 |
+
'''
|
| 384 |
+
|
| 385 |
def main():
|
| 386 |
st.sidebar.markdown("### π²BikeAIπ Claude and GPT Multi-Agent Research AI")
|
| 387 |
|