Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,7 +31,7 @@ from urllib.parse import quote
|
|
| 31 |
from xml.etree import ElementTree as ET
|
| 32 |
from openai import OpenAI
|
| 33 |
|
| 34 |
-
# 1. Configuration and Setup
|
| 35 |
Site_Name = '🚲BikeAI🏆 Claude and GPT Multi-Agent Research AI'
|
| 36 |
title = "🚲BikeAI🏆 Claude and GPT Multi-Agent Research AI"
|
| 37 |
helpURL = 'https://huggingface.co/awacke1'
|
|
@@ -50,7 +50,7 @@ st.set_page_config(
|
|
| 50 |
}
|
| 51 |
)
|
| 52 |
|
| 53 |
-
# 2. Load environment variables and initialize clients
|
| 54 |
load_dotenv()
|
| 55 |
|
| 56 |
# OpenAI setup
|
|
@@ -63,13 +63,13 @@ openai_client = OpenAI(
|
|
| 63 |
organization=os.getenv('OPENAI_ORG_ID')
|
| 64 |
)
|
| 65 |
|
| 66 |
-
# 3
|
| 67 |
anthropic_key = os.getenv("ANTHROPIC_API_KEY_3")
|
| 68 |
if anthropic_key == None:
|
| 69 |
anthropic_key = st.secrets["ANTHROPIC_API_KEY"]
|
| 70 |
claude_client = anthropic.Anthropic(api_key=anthropic_key)
|
| 71 |
|
| 72 |
-
# 4
|
| 73 |
if 'transcript_history' not in st.session_state:
|
| 74 |
st.session_state.transcript_history = []
|
| 75 |
if "chat_history" not in st.session_state:
|
|
@@ -81,26 +81,17 @@ if "messages" not in st.session_state:
|
|
| 81 |
if 'last_voice_input' not in st.session_state:
|
| 82 |
st.session_state.last_voice_input = ""
|
| 83 |
|
| 84 |
-
# 5.
|
| 85 |
API_URL = os.getenv('API_URL')
|
| 86 |
HF_KEY = os.getenv('HF_KEY')
|
| 87 |
MODEL1 = "meta-llama/Llama-2-7b-chat-hf"
|
| 88 |
MODEL2 = "openai/whisper-small.en"
|
| 89 |
-
|
| 90 |
headers = {
|
| 91 |
"Authorization": f"Bearer {HF_KEY}",
|
| 92 |
"Content-Type": "application/json"
|
| 93 |
}
|
| 94 |
|
| 95 |
-
#
|
| 96 |
-
if "chat_history" not in st.session_state:
|
| 97 |
-
st.session_state.chat_history = []
|
| 98 |
-
if "openai_model" not in st.session_state:
|
| 99 |
-
st.session_state["openai_model"] = "gpt-4o-2024-05-13"
|
| 100 |
-
if "messages" not in st.session_state:
|
| 101 |
-
st.session_state.messages = []
|
| 102 |
-
|
| 103 |
-
# Custom CSS
|
| 104 |
st.markdown("""
|
| 105 |
<style>
|
| 106 |
.main {
|
|
@@ -141,59 +132,6 @@ st.markdown("""
|
|
| 141 |
""", unsafe_allow_html=True)
|
| 142 |
|
| 143 |
|
| 144 |
-
# Bike Collections
|
| 145 |
-
bike_collections = {
|
| 146 |
-
"Celestial Collection 🌌": {
|
| 147 |
-
"Eclipse Vaulter": {
|
| 148 |
-
"prompt": """Cinematic shot of a sleek black mountain bike silhouetted against a total solar eclipse.
|
| 149 |
-
The corona creates an ethereal halo effect, with lens flares accentuating key points of the frame.
|
| 150 |
-
Dynamic composition shows the bike mid-leap, with stardust particles trailing behind.
|
| 151 |
-
Camera angle: Low angle, wide shot
|
| 152 |
-
Lighting: Dramatic rim lighting from eclipse
|
| 153 |
-
Color palette: Deep purples, cosmic blues, corona gold""",
|
| 154 |
-
"emoji": "🌑"
|
| 155 |
-
},
|
| 156 |
-
"Starlight Leaper": {
|
| 157 |
-
"prompt": """A black bike performing an epic leap under a vast Milky Way galaxy.
|
| 158 |
-
Shimmering stars blanket the sky while the bike's wheels leave a trail of stardust.
|
| 159 |
-
Camera angle: Wide-angle upward shot
|
| 160 |
-
Lighting: Natural starlight with subtle rim lighting
|
| 161 |
-
Color palette: Deep blues, silver highlights, cosmic purples""",
|
| 162 |
-
"emoji": "✨"
|
| 163 |
-
},
|
| 164 |
-
"Moonlit Hopper": {
|
| 165 |
-
"prompt": """A sleek black bike mid-hop over a moonlit meadow,
|
| 166 |
-
the full moon illuminating the misty surroundings. Fireflies dance around the bike,
|
| 167 |
-
and soft shadows create a serene yet dynamic atmosphere.
|
| 168 |
-
Camera angle: Side profile with slight low angle
|
| 169 |
-
Lighting: Soft moonlight with atmospheric fog
|
| 170 |
-
Color palette: Silver blues, soft whites, deep shadows""",
|
| 171 |
-
"emoji": "🌙"
|
| 172 |
-
}
|
| 173 |
-
},
|
| 174 |
-
"Nature-Inspired Collection 🌲": {
|
| 175 |
-
"Shadow Grasshopper": {
|
| 176 |
-
"prompt": """A black bike jumping between forest paths,
|
| 177 |
-
with dappled sunlight streaming through the canopy. Shadows dance on the bike's frame
|
| 178 |
-
as it soars above mossy logs.
|
| 179 |
-
Camera angle: Through-the-trees tracking shot
|
| 180 |
-
Lighting: Natural forest lighting with sun rays
|
| 181 |
-
Color palette: Forest greens, golden sunlight, deep shadows""",
|
| 182 |
-
"emoji": "🦗"
|
| 183 |
-
},
|
| 184 |
-
"Onyx Leapfrog": {
|
| 185 |
-
"prompt": """A bike with obsidian-black finish jumping over a sparkling creek,
|
| 186 |
-
the reflection on the water broken into ripples by the leap. The surrounding forest
|
| 187 |
-
is vibrant with greens and browns.
|
| 188 |
-
Camera angle: Low angle from water level
|
| 189 |
-
Lighting: Golden hour side lighting
|
| 190 |
-
Color palette: Deep blacks, water blues, forest greens""",
|
| 191 |
-
"emoji": "🐸"
|
| 192 |
-
}
|
| 193 |
-
}
|
| 194 |
-
}
|
| 195 |
-
|
| 196 |
-
|
| 197 |
# Helper Functions
|
| 198 |
def generate_filename(prompt, file_type):
|
| 199 |
"""Generate a safe filename using the prompt and file type."""
|
|
@@ -565,7 +503,7 @@ def create_media_gallery():
|
|
| 565 |
"""Create the media gallery interface."""
|
| 566 |
st.header("🎬 Media Gallery")
|
| 567 |
|
| 568 |
-
tabs = st.tabs(["🖼️ Images", "🎵 Audio", "🎥 Video"
|
| 569 |
|
| 570 |
with tabs[0]:
|
| 571 |
image_files = glob.glob("*.png") + glob.glob("*.jpg")
|
|
@@ -603,25 +541,7 @@ def create_media_gallery():
|
|
| 603 |
"Describe what's happening in this video.")
|
| 604 |
st.markdown(analysis)
|
| 605 |
|
| 606 |
-
|
| 607 |
-
for collection_name, bikes in bike_collections.items():
|
| 608 |
-
st.subheader(collection_name)
|
| 609 |
-
cols = st.columns(len(bikes))
|
| 610 |
-
|
| 611 |
-
for idx, (bike_name, details) in enumerate(bikes.items()):
|
| 612 |
-
with cols[idx]:
|
| 613 |
-
st.markdown(f"""
|
| 614 |
-
<div class='bike-card'>
|
| 615 |
-
<h3>{details['emoji']} {bike_name}</h3>
|
| 616 |
-
<p>{details['prompt']}</p>
|
| 617 |
-
</div>
|
| 618 |
-
""", unsafe_allow_html=True)
|
| 619 |
-
|
| 620 |
-
if st.button(f"Generate {bike_name} Scene"):
|
| 621 |
-
prompt = details['prompt']
|
| 622 |
-
# Here you could integrate with image generation API
|
| 623 |
-
st.write(f"Generated scene description for {bike_name}:")
|
| 624 |
-
st.write(prompt)
|
| 625 |
|
| 626 |
def display_file_manager():
|
| 627 |
"""Display file management sidebar with guaranteed unique button keys."""
|
|
@@ -973,7 +893,7 @@ def create_media_gallery():
|
|
| 973 |
"""Create the media gallery interface."""
|
| 974 |
st.header("🎬 Media Gallery")
|
| 975 |
|
| 976 |
-
tabs = st.tabs(["🖼️ Images", "🎵 Audio", "🎥 Video"
|
| 977 |
|
| 978 |
with tabs[0]:
|
| 979 |
image_files = glob.glob("*.png") + glob.glob("*.jpg")
|
|
@@ -1011,25 +931,7 @@ def create_media_gallery():
|
|
| 1011 |
"Describe what's happening in this video.")
|
| 1012 |
st.markdown(analysis)
|
| 1013 |
|
| 1014 |
-
|
| 1015 |
-
for collection_name, bikes in bike_collections.items():
|
| 1016 |
-
st.subheader(collection_name)
|
| 1017 |
-
cols = st.columns(len(bikes))
|
| 1018 |
-
|
| 1019 |
-
for idx, (bike_name, details) in enumerate(bikes.items()):
|
| 1020 |
-
with cols[idx]:
|
| 1021 |
-
st.markdown(f"""
|
| 1022 |
-
<div class='bike-card'>
|
| 1023 |
-
<h3>{details['emoji']} {bike_name}</h3>
|
| 1024 |
-
<p>{details['prompt']}</p>
|
| 1025 |
-
</div>
|
| 1026 |
-
""", unsafe_allow_html=True)
|
| 1027 |
-
|
| 1028 |
-
if st.button(f"Generate {bike_name} Scene"):
|
| 1029 |
-
prompt = details['prompt']
|
| 1030 |
-
# Here you could integrate with image generation API
|
| 1031 |
-
st.write(f"Generated scene description for {bike_name}:")
|
| 1032 |
-
st.write(prompt)
|
| 1033 |
|
| 1034 |
def get_media_html(media_path, media_type="video", width="100%"):
|
| 1035 |
"""Generate HTML for media player."""
|
|
|
|
| 31 |
from xml.etree import ElementTree as ET
|
| 32 |
from openai import OpenAI
|
| 33 |
|
| 34 |
+
# 1. 🚲BikeAI🏆 Configuration and Setup
|
| 35 |
Site_Name = '🚲BikeAI🏆 Claude and GPT Multi-Agent Research AI'
|
| 36 |
title = "🚲BikeAI🏆 Claude and GPT Multi-Agent Research AI"
|
| 37 |
helpURL = 'https://huggingface.co/awacke1'
|
|
|
|
| 50 |
}
|
| 51 |
)
|
| 52 |
|
| 53 |
+
# 2. 🚲BikeAI🏆 Load environment variables and initialize clients
|
| 54 |
load_dotenv()
|
| 55 |
|
| 56 |
# OpenAI setup
|
|
|
|
| 63 |
organization=os.getenv('OPENAI_ORG_ID')
|
| 64 |
)
|
| 65 |
|
| 66 |
+
# 3.🚲BikeAI🏆 Claude setup
|
| 67 |
anthropic_key = os.getenv("ANTHROPIC_API_KEY_3")
|
| 68 |
if anthropic_key == None:
|
| 69 |
anthropic_key = st.secrets["ANTHROPIC_API_KEY"]
|
| 70 |
claude_client = anthropic.Anthropic(api_key=anthropic_key)
|
| 71 |
|
| 72 |
+
# 4.🚲BikeAI🏆 Initialize session states
|
| 73 |
if 'transcript_history' not in st.session_state:
|
| 74 |
st.session_state.transcript_history = []
|
| 75 |
if "chat_history" not in st.session_state:
|
|
|
|
| 81 |
if 'last_voice_input' not in st.session_state:
|
| 82 |
st.session_state.last_voice_input = ""
|
| 83 |
|
| 84 |
+
# 5. 🚲BikeAI🏆 HuggingFace AI setup
|
| 85 |
API_URL = os.getenv('API_URL')
|
| 86 |
HF_KEY = os.getenv('HF_KEY')
|
| 87 |
MODEL1 = "meta-llama/Llama-2-7b-chat-hf"
|
| 88 |
MODEL2 = "openai/whisper-small.en"
|
|
|
|
| 89 |
headers = {
|
| 90 |
"Authorization": f"Bearer {HF_KEY}",
|
| 91 |
"Content-Type": "application/json"
|
| 92 |
}
|
| 93 |
|
| 94 |
+
# 🚲BikeAI🏆 Custom CSS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
st.markdown("""
|
| 96 |
<style>
|
| 97 |
.main {
|
|
|
|
| 132 |
""", unsafe_allow_html=True)
|
| 133 |
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
# Helper Functions
|
| 136 |
def generate_filename(prompt, file_type):
|
| 137 |
"""Generate a safe filename using the prompt and file type."""
|
|
|
|
| 503 |
"""Create the media gallery interface."""
|
| 504 |
st.header("🎬 Media Gallery")
|
| 505 |
|
| 506 |
+
tabs = st.tabs(["🖼️ Images", "🎵 Audio", "🎥 Video"])
|
| 507 |
|
| 508 |
with tabs[0]:
|
| 509 |
image_files = glob.glob("*.png") + glob.glob("*.jpg")
|
|
|
|
| 541 |
"Describe what's happening in this video.")
|
| 542 |
st.markdown(analysis)
|
| 543 |
|
| 544 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 545 |
|
| 546 |
def display_file_manager():
|
| 547 |
"""Display file management sidebar with guaranteed unique button keys."""
|
|
|
|
| 893 |
"""Create the media gallery interface."""
|
| 894 |
st.header("🎬 Media Gallery")
|
| 895 |
|
| 896 |
+
tabs = st.tabs(["🖼️ Images", "🎵 Audio", "🎥 Video"])
|
| 897 |
|
| 898 |
with tabs[0]:
|
| 899 |
image_files = glob.glob("*.png") + glob.glob("*.jpg")
|
|
|
|
| 931 |
"Describe what's happening in this video.")
|
| 932 |
st.markdown(analysis)
|
| 933 |
|
| 934 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 935 |
|
| 936 |
def get_media_html(media_path, media_type="video", width="100%"):
|
| 937 |
"""Generate HTML for media player."""
|