Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
# requirements.txt additions: | |
""" | |
streamlit-marquee | |
""" | |
# app.py | |
import streamlit as st | |
import anthropic, openai, base64, cv2, glob, json, math, os, pytz, random, re, requests, time, zipfile | |
import plotly.graph_objects as go | |
import streamlit.components.v1 as components | |
from datetime import datetime | |
from audio_recorder_streamlit import audio_recorder | |
from collections import defaultdict, deque, Counter | |
from dotenv import load_dotenv | |
from gradio_client import Client | |
from huggingface_hub import InferenceClient | |
from io import BytesIO | |
from PIL import Image | |
from PyPDF2 import PdfReader | |
from urllib.parse import quote | |
from xml.etree import ElementTree as ET | |
from openai import OpenAI | |
import extra_streamlit_components as stx | |
import asyncio | |
import edge_tts | |
from streamlit_marquee import st_marquee | |
# Core setup | |
st.set_page_config( | |
page_title="๐ฒTalkingAIResearcher๐", | |
page_icon="๐ฒ๐", | |
layout="wide", | |
initial_sidebar_state="auto", | |
) | |
# Initialize session state | |
if 'tts_voice' not in st.session_state: | |
st.session_state['tts_voice'] = "en-US-AriaNeural" | |
if 'audio_format' not in st.session_state: | |
st.session_state['audio_format'] = 'mp3' | |
if 'scroll_text' not in st.session_state: | |
st.session_state['scroll_text'] = '' | |
EDGE_TTS_VOICES = [ | |
"en-US-AriaNeural", | |
"en-US-GuyNeural", | |
"en-US-JennyNeural", | |
"en-GB-SoniaNeural", | |
] | |
FILE_EMOJIS = { | |
"md": "๐", | |
"mp3": "๐ต", | |
"wav": "๐", | |
"txt": "๐", | |
"pdf": "๐", | |
"json": "๐", | |
"csv": "๐", | |
"zip": "๐ฆ" | |
} | |
def get_cached_audio_b64(file_path): | |
"""Cache audio file as base64""" | |
with open(file_path, "rb") as f: | |
return base64.b64encode(f.read()).decode() | |
def beautify_filename(filename): | |
"""Make filename more readable""" | |
name = os.path.splitext(filename)[0] | |
name = name.replace('_', ' ').replace('.', ' ') | |
return name | |
def load_files_for_sidebar(): | |
"""Load and group files by timestamp prefix""" | |
md_files = glob.glob("*.md") | |
mp3_files = glob.glob("*.mp3") | |
wav_files = glob.glob("*.wav") | |
md_files = [f for f in md_files if os.path.basename(f).lower() != 'readme.md'] | |
all_files = md_files + mp3_files + wav_files | |
groups = defaultdict(list) | |
for f in all_files: | |
basename = os.path.basename(f) | |
group_name = basename[:9] if len(basename) >= 9 else 'Other' | |
groups[group_name].append(f) | |
return sorted(groups.items(), | |
key=lambda x: max(os.path.getmtime(f) for f in x[1]), | |
reverse=True) | |
def display_file_manager_sidebar(groups_sorted): | |
"""Enhanced sidebar with audio players and beautified names""" | |
st.sidebar.title("๐ File Manager") | |
all_md, all_mp3, all_wav = [], [], [] | |
for _, files in groups_sorted: | |
for f in files: | |
if f.endswith(".md"): all_md.append(f) | |
elif f.endswith(".mp3"): all_mp3.append(f) | |
elif f.endswith(".wav"): all_wav.append(f) | |
# File management buttons | |
cols = st.sidebar.columns(4) | |
with cols[0]: | |
if st.button("๐๏ธ MD"): | |
[os.remove(f) for f in all_md] | |
st.session_state.should_rerun = True | |
with cols[1]: | |
if st.button("๐๏ธ MP3"): | |
[os.remove(f) for f in all_mp3] | |
st.session_state.should_rerun = True | |
with cols[2]: | |
if st.button("๐๏ธ WAV"): | |
[os.remove(f) for f in all_wav] | |
st.session_state.should_rerun = True | |
with cols[3]: | |
if st.button("๐ฆ Zip"): | |
zip_name = create_zip_of_files(all_md, all_mp3, all_wav, | |
st.session_state.get('last_query', '')) | |
if zip_name: | |
st.sidebar.markdown(get_download_link(zip_name), unsafe_allow_html=True) | |
# Display file groups | |
for group_name, files in groups_sorted: | |
timestamp_dt = datetime.strptime(group_name, "%y%m_%H%M") if len(group_name) == 9 else None | |
group_label = timestamp_dt.strftime("%Y-%m-%d %H:%M") if timestamp_dt else group_name | |
with st.sidebar.expander(f"๐ {group_label} ({len(files)})", expanded=True): | |
c1, c2 = st.columns(2) | |
with c1: | |
if st.button("๐", key=f"view_{group_name}"): | |
st.session_state.viewing_prefix = group_name | |
with c2: | |
if st.button("๐๏ธ", key=f"del_{group_name}"): | |
[os.remove(f) for f in files] | |
st.session_state.should_rerun = True | |
for f in files: | |
ext = os.path.splitext(f)[1].lower().strip('.') | |
emoji = FILE_EMOJIS.get(ext, '๐') | |
pretty_name = beautify_filename(os.path.basename(f)) | |
st.write(f"{emoji} **{pretty_name}**") | |
if ext in ['mp3', 'wav']: | |
audio_b64 = get_cached_audio_b64(f) | |
st.audio(f) | |
cols = st.columns([3,1]) | |
with cols[1]: | |
if st.button("๐", key=f"loop_{f}"): | |
components.html( | |
f''' | |
<audio id="player_{f}" loop> | |
<source src="data:audio/{ext};base64,{audio_b64}"> | |
</audio> | |
<script> | |
document.getElementById("player_{f}").play(); | |
</script> | |
''', | |
height=0 | |
) | |
def main(): | |
# Add scrolling banner | |
st_marquee( | |
text=" | ".join(st.session_state.get('scroll_text', '๐ Welcome to TalkingAIResearcher').split('\n')), | |
font_size=20, | |
) | |
# Rest of the main UI code... | |
# (Keep existing main() implementation but with beautified filenames) | |
# Compressed sidebar markdown | |
sidebar_md = """ | |
# ๐ง AGI Levels | |
L0 โ No AI | |
L1 ๐ฑ Emerging (ChatGPT, Bard) | |
L2 ๐ช Competent (Watson) | |
L3 ๐ฏ Expert (DALLยทE) | |
L4 ๐ Virtuoso (AlphaGo) | |
L5 ๐ Superhuman (AlphaFold) | |
# ๐งฌ AlphaFold2 | |
1. ๐งฌ Input Seq | |
2. ๐ DB Search | |
3. ๐งฉ MSA | |
4. ๐ Templates | |
5. ๐ Evoformer | |
6. ๐งฑ Structure | |
7. ๐ฏ 3D Predict | |
8. โป๏ธ Recycle x3 | |
""" | |
if __name__=="__main__": | |
main() |