awacke1 commited on
Commit
2fbbcd1
1 Parent(s): fe0c703

Update backup8app.py

Browse files
Files changed (1) hide show
  1. backup8app.py +59 -22
backup8app.py CHANGED
@@ -31,6 +31,11 @@ from urllib.parse import quote
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"
@@ -91,7 +96,7 @@ headers = {
91
  "Content-Type": "application/json"
92
  }
93
 
94
- # 🚲BikeAI🏆 Custom CSS
95
  st.markdown("""
96
  <style>
97
  .main {
@@ -132,7 +137,7 @@ st.markdown("""
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."""
138
  central = pytz.timezone('US/Central')
@@ -144,15 +149,12 @@ def generate_filename(prompt, file_type):
144
 
145
 
146
 
147
- # Function to create and save a file (and avoid the black hole of lost data 🕳)
148
  def create_file(filename, prompt, response, should_save=True):
149
  if not should_save:
150
  return
151
  with open(filename, 'w', encoding='utf-8') as file:
152
  file.write(prompt + "\n\n" + response)
153
-
154
-
155
-
156
  def create_and_save_file(content, file_type="md", prompt=None, is_image=False, should_save=True):
157
  """Create and save file with proper handling of different types."""
158
  if not should_save:
@@ -165,6 +167,7 @@ def create_and_save_file(content, file_type="md", prompt=None, is_image=False, s
165
  f.write(prompt + "\n\n" + content if prompt else content)
166
  return filename
167
 
 
168
  def get_download_link(file_path):
169
  """Create download link for file."""
170
  with open(file_path, "rb") as file:
@@ -708,6 +711,7 @@ speech_recognition_html = """
708
  }
709
  lastUpdateTime = Date.now();
710
  }
 
711
 
712
  output.textContent = fullTranscript + (interimTranscript ? '... ' + interimTranscript : '');
713
  output.scrollTop = output.scrollHeight;
@@ -867,21 +871,10 @@ def get_media_html(media_path, media_type="video", width="100%"):
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")
@@ -896,6 +889,51 @@ def main():
896
 
897
  # Display speech recognition component
898
  speech_component = st.components.v1.html(speech_recognition_html, height=400)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
899
 
900
  # Handle speech recognition output
901
  if speech_component:
@@ -1014,7 +1052,6 @@ def main():
1014
  st.success("File updated successfully!")
1015
 
1016
 
1017
-
1018
  # Always show file manager in sidebar
1019
  display_file_manager()
1020
 
 
31
  from xml.etree import ElementTree as ET
32
  from openai import OpenAI
33
 
34
+
35
+
36
+
37
+
38
+
39
  # 1. 🚲BikeAI🏆 Configuration and Setup
40
  Site_Name = '🚲BikeAI🏆 Claude and GPT Multi-Agent Research AI'
41
  title = "🚲BikeAI🏆 Claude and GPT Multi-Agent Research AI"
 
96
  "Content-Type": "application/json"
97
  }
98
 
99
+ # 6. 🚲BikeAI🏆 Custom CSS
100
  st.markdown("""
101
  <style>
102
  .main {
 
137
  """, unsafe_allow_html=True)
138
 
139
 
140
+ # 7. Helper Functions
141
  def generate_filename(prompt, file_type):
142
  """Generate a safe filename using the prompt and file type."""
143
  central = pytz.timezone('US/Central')
 
149
 
150
 
151
 
152
+ # 8. Function to create and save a file (and avoid the black hole of lost data 🕳)
153
  def create_file(filename, prompt, response, should_save=True):
154
  if not should_save:
155
  return
156
  with open(filename, 'w', encoding='utf-8') as file:
157
  file.write(prompt + "\n\n" + response)
 
 
 
158
  def create_and_save_file(content, file_type="md", prompt=None, is_image=False, should_save=True):
159
  """Create and save file with proper handling of different types."""
160
  if not should_save:
 
167
  f.write(prompt + "\n\n" + content if prompt else content)
168
  return filename
169
 
170
+
171
  def get_download_link(file_path):
172
  """Create download link for file."""
173
  with open(file_path, "rb") as file:
 
711
  }
712
  lastUpdateTime = Date.now();
713
  }
714
+
715
 
716
  output.textContent = fullTranscript + (interimTranscript ? '... ' + interimTranscript : '');
717
  output.scrollTop = output.scrollHeight;
 
871
  </audio>
872
  '''
873
 
874
+ @st.cache_resource
875
+ def set_transcript(text):
876
+ """Set transcript in session state."""
877
+ st.session_state.voice_transcript = text
 
 
 
 
 
 
 
 
 
 
 
878
 
879
  def main():
880
  st.sidebar.markdown("### 🚲BikeAI🏆 Claude and GPT Multi-Agent Research AI")
 
889
 
890
  # Display speech recognition component
891
  speech_component = st.components.v1.html(speech_recognition_html, height=400)
892
+
893
+
894
+ #Experiment: Use `st.session_state` to store the transcript
895
+
896
+
897
+ # Listen to messages from the HTML component
898
+ components.html("""
899
+ <script>
900
+ window.addEventListener('message', (event) => {
901
+ if (event.data.type === 'final_transcript') {
902
+ const transcript = event.data.text;
903
+ Streamlit.setComponentValue(transcript);
904
+ }
905
+ });
906
+ </script>
907
+ """, height=0)
908
+
909
+
910
+ if 'voice_transcript' not in st.session_state:
911
+ st.session_state.voice_transcript = ""
912
+
913
+ # Check for updates to transcript
914
+ if st.session_state.voice_transcript:
915
+ st.markdown("### Processed Voice Input:")
916
+ st.text_area("Voice Transcript", st.session_state.voice_transcript, height=100)
917
+
918
+ # Buttons to process the transcript
919
+ if st.button("Search with GPT"):
920
+ st.subheader("GPT-4o Response")
921
+ gpt_response = process_with_gpt(st.session_state.voice_transcript)
922
+ st.markdown(gpt_response)
923
+
924
+ if st.button("Search with Claude"):
925
+ st.subheader("Claude Response")
926
+ claude_response = process_with_claude(st.session_state.voice_transcript)
927
+ st.markdown(claude_response)
928
+
929
+ if st.button("Search ArXiv"):
930
+ st.subheader("ArXiv Search Results")
931
+ arxiv_results = perform_ai_lookup(st.session_state.voice_transcript)
932
+ st.markdown(arxiv_results)
933
+ # Clear transcript button
934
+ if st.button("Clear Transcript"):
935
+ st.session_state.voice_transcript = ""
936
+
937
 
938
  # Handle speech recognition output
939
  if speech_component:
 
1052
  st.success("File updated successfully!")
1053
 
1054
 
 
1055
  # Always show file manager in sidebar
1056
  display_file_manager()
1057