awacke1 commited on
Commit
dbb9da3
ยท
verified ยท
1 Parent(s): bf7933c

Update backup8app.py

Browse files
Files changed (1) hide show
  1. backup8app.py +81 -196
backup8app.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. 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. 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,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. # HuggingFace 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
-
90
  headers = {
91
  "Authorization": f"Bearer {HF_KEY}",
92
  "Content-Type": "application/json"
93
  }
94
 
95
- # Initialize session states
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", "๐ŸŽจ Scene Generator"])
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
- with tabs[3]:
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."""
@@ -662,91 +582,7 @@ def display_file_manager():
662
  st.rerun()
663
 
664
 
665
- def main():
666
- st.sidebar.markdown("### ๐ŸšฒBikeAI๐Ÿ† Claude and GPT Multi-Agent Research AI")
667
-
668
- # Main navigation
669
- tab_main = st.radio("Choose Action:",
670
- ["๐Ÿ’ฌ Chat", "๐Ÿ“ธ Media Gallery", "๐Ÿ” Search ArXiv", "๐Ÿ“ File Editor"],
671
- horizontal=True)
672
-
673
- if tab_main == "๐Ÿ’ฌ Chat":
674
- # Model Selection
675
- model_choice = st.sidebar.radio(
676
- "Choose AI Model:",
677
- ["GPT-4o", "Claude-3", "GPT+Claude+Arxiv"]
678
- )
679
-
680
- # Chat Interface
681
- user_input = st.text_area("Message:", height=100)
682
-
683
- if st.button("Send ๐Ÿ“จ"):
684
- if user_input:
685
- if model_choice == "GPT-4o":
686
- gpt_response = process_with_gpt(user_input)
687
- elif model_choice == "Claude-3":
688
- claude_response = process_with_claude(user_input)
689
- else: # Both
690
- col1, col2, col3 = st.columns(3)
691
- with col2:
692
- st.subheader("Claude-3.5 Sonnet:")
693
- try:
694
- claude_response = process_with_claude(user_input)
695
- except:
696
- st.write('Claude 3.5 Sonnet out of tokens.')
697
- with col1:
698
- st.subheader("GPT-4o Omni:")
699
- try:
700
- gpt_response = process_with_gpt(user_input)
701
- except:
702
- st.write('GPT 4o out of tokens')
703
- with col3:
704
- st.subheader("Arxiv and Mistral Research:")
705
- with st.spinner("Searching ArXiv..."):
706
- #results = search_arxiv(user_input)
707
- results = perform_ai_lookup(user_input)
708
-
709
- st.markdown(results)
710
-
711
- # Display Chat History
712
- st.subheader("Chat History ๐Ÿ“œ")
713
- tab1, tab2 = st.tabs(["Claude History", "GPT-4o History"])
714
-
715
- with tab1:
716
- for chat in st.session_state.chat_history:
717
- st.text_area("You:", chat["user"], height=100)
718
- st.text_area("Claude:", chat["claude"], height=200)
719
- st.markdown(chat["claude"])
720
-
721
- with tab2:
722
- for message in st.session_state.messages:
723
- with st.chat_message(message["role"]):
724
- st.markdown(message["content"])
725
-
726
- elif tab_main == "๐Ÿ“ธ Media Gallery":
727
- create_media_gallery()
728
-
729
- elif tab_main == "๐Ÿ” Search ArXiv":
730
- query = st.text_input("Enter your research query:")
731
- if query:
732
- with st.spinner("Searching ArXiv..."):
733
- results = search_arxiv(query)
734
- st.markdown(results)
735
-
736
- elif tab_main == "๐Ÿ“ File Editor":
737
- if hasattr(st.session_state, 'current_file'):
738
- st.subheader(f"Editing: {st.session_state.current_file}")
739
- new_content = st.text_area("Content:", st.session_state.file_content, height=300)
740
- if st.button("Save Changes"):
741
- with open(st.session_state.current_file, 'w', encoding='utf-8') as file:
742
- file.write(new_content)
743
- st.success("File updated successfully!")
744
-
745
- # Always show file manager in sidebar
746
- display_file_manager()
747
 
748
- if __name__ == "__main__":
749
- main()
750
 
751
  # Speech Recognition HTML Component
752
  speech_recognition_html = """
@@ -973,7 +809,7 @@ def create_media_gallery():
973
  """Create the media gallery interface."""
974
  st.header("๐ŸŽฌ Media Gallery")
975
 
976
- tabs = st.tabs(["๐Ÿ–ผ๏ธ Images", "๐ŸŽต Audio", "๐ŸŽฅ Video", "๐ŸŽจ Scene Generator"])
977
 
978
  with tabs[0]:
979
  image_files = glob.glob("*.png") + glob.glob("*.jpg")
@@ -1011,25 +847,7 @@ def create_media_gallery():
1011
  "Describe what's happening in this video.")
1012
  st.markdown(analysis)
1013
 
1014
- with tabs[3]:
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."""
@@ -1048,6 +866,22 @@ def get_media_html(media_path, media_type="video", width="100%"):
1048
  Your browser does not support the audio element.
1049
  </audio>
1050
  '''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1051
 
1052
  def main():
1053
  st.sidebar.markdown("### ๐ŸšฒBikeAI๐Ÿ† Claude and GPT Multi-Agent Research AI")
@@ -1106,10 +940,59 @@ def main():
1106
  if st.session_state.last_voice_input:
1107
  st.text_area("Last Voice Input:", st.session_state.last_voice_input, height=100)
1108
 
1109
- # [Rest of the main function remains the same]
1110
- elif tab_main == "๐Ÿ’ฌ Chat":
1111
- # [Previous chat interface code]
1112
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1113
 
1114
  elif tab_main == "๐Ÿ“ธ Media Gallery":
1115
  create_media_gallery()
@@ -1129,6 +1012,8 @@ def main():
1129
  with open(st.session_state.current_file, 'w', encoding='utf-8') as file:
1130
  file.write(new_content)
1131
  st.success("File updated successfully!")
 
 
1132
 
1133
  # Always show file manager in sidebar
1134
  display_file_manager()
 
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."""
 
582
  st.rerun()
583
 
584
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
585
 
 
 
586
 
587
  # Speech Recognition HTML Component
588
  speech_recognition_html = """
 
809
  """Create the media gallery interface."""
810
  st.header("๐ŸŽฌ Media Gallery")
811
 
812
+ tabs = st.tabs(["๐Ÿ–ผ๏ธ Images", "๐ŸŽต Audio", "๐ŸŽฅ Video"])
813
 
814
  with tabs[0]:
815
  image_files = glob.glob("*.png") + glob.glob("*.jpg")
 
847
  "Describe what's happening in this video.")
848
  st.markdown(analysis)
849
 
850
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
851
 
852
  def get_media_html(media_path, media_type="video", width="100%"):
853
  """Generate HTML for media player."""
 
866
  Your browser does not support the audio element.
867
  </audio>
868
  '''
869
+
870
+
871
+ def main_old():
872
+
873
+ # Main navigation
874
+ tab_main = st.radio("Choose Action:",
875
+ ["๐Ÿ’ฌ Chat", "๐Ÿ“ธ Media Gallery", "๐Ÿ” Search ArXiv", "๐Ÿ“ File Editor"],
876
+ horizontal=True)
877
+
878
+ # Always show file manager in sidebar
879
+ # display_file_manager()
880
+
881
+ #if __name__ == "__main__":
882
+ # main()
883
+
884
+
885
 
886
  def main():
887
  st.sidebar.markdown("### ๐ŸšฒBikeAI๐Ÿ† Claude and GPT Multi-Agent Research AI")
 
940
  if st.session_state.last_voice_input:
941
  st.text_area("Last Voice Input:", st.session_state.last_voice_input, height=100)
942
 
943
+
944
+ if tab_main == "๐Ÿ’ฌ Chat":
945
+ # Model Selection
946
+ model_choice = st.sidebar.radio(
947
+ "Choose AI Model:",
948
+ ["GPT-4o", "Claude-3", "GPT+Claude+Arxiv"]
949
+ )
950
+
951
+ # Chat Interface
952
+ user_input = st.text_area("Message:", height=100)
953
+
954
+ if st.button("Send ๐Ÿ“จ"):
955
+ if user_input:
956
+ if model_choice == "GPT-4o":
957
+ gpt_response = process_with_gpt(user_input)
958
+ elif model_choice == "Claude-3":
959
+ claude_response = process_with_claude(user_input)
960
+ else: # Both
961
+ col1, col2, col3 = st.columns(3)
962
+ with col2:
963
+ st.subheader("Claude-3.5 Sonnet:")
964
+ try:
965
+ claude_response = process_with_claude(user_input)
966
+ except:
967
+ st.write('Claude 3.5 Sonnet out of tokens.')
968
+ with col1:
969
+ st.subheader("GPT-4o Omni:")
970
+ try:
971
+ gpt_response = process_with_gpt(user_input)
972
+ except:
973
+ st.write('GPT 4o out of tokens')
974
+ with col3:
975
+ st.subheader("Arxiv and Mistral Research:")
976
+ with st.spinner("Searching ArXiv..."):
977
+ #results = search_arxiv(user_input)
978
+ results = perform_ai_lookup(user_input)
979
+
980
+ st.markdown(results)
981
+
982
+ # Display Chat History
983
+ st.subheader("Chat History ๐Ÿ“œ")
984
+ tab1, tab2 = st.tabs(["Claude History", "GPT-4o History"])
985
+
986
+ with tab1:
987
+ for chat in st.session_state.chat_history:
988
+ st.text_area("You:", chat["user"], height=100)
989
+ st.text_area("Claude:", chat["claude"], height=200)
990
+ st.markdown(chat["claude"])
991
+
992
+ with tab2:
993
+ for message in st.session_state.messages:
994
+ with st.chat_message(message["role"]):
995
+ st.markdown(message["content"])
996
 
997
  elif tab_main == "๐Ÿ“ธ Media Gallery":
998
  create_media_gallery()
 
1012
  with open(st.session_state.current_file, 'w', encoding='utf-8') as file:
1013
  file.write(new_content)
1014
  st.success("File updated successfully!")
1015
+
1016
+
1017
 
1018
  # Always show file manager in sidebar
1019
  display_file_manager()