hjawwad456 commited on
Commit
da561f9
·
1 Parent(s): 898b233

add firebase head

Browse files
Files changed (1) hide show
  1. app.py +72 -36
app.py CHANGED
@@ -862,48 +862,84 @@ def create_chat_interface():
862
  cursor: progress;
863
  }
864
  """
865
- js = """
866
- function createIframeHandler() {
867
- let iframe = document.getElementById('link-frame');
868
- if (!iframe) {
869
- iframe = document.createElement('iframe');
870
- iframe.id = 'link-frame';
871
- iframe.style.position = 'absolute';
872
- iframe.style.width = '1px';
873
- iframe.style.height = '1px';
874
- iframe.style.right = '-100px';
875
- iframe.style.bottom = '-100px';
876
- iframe.style.display = 'none'; // Hidden initially
877
- document.body.appendChild(iframe);
878
- }
879
-
880
- document.addEventListener('click', function (event) {
881
- var link = event.target.closest('a');
882
- if (link && link.href) {
883
- document.body.classList.add('waiting');
884
- setTimeout(function () {
885
- document.body.classList.remove('waiting');
886
- }, 2000); // Reset cursor after 1 seconds
887
- try {
888
- iframe.src = link.href;
889
- iframe.style.display = 'block'; // Show iframe on link click
890
- event.preventDefault();
891
- console.log('Opening link in iframe:', link.href);
892
- } catch (error) {
893
- console.error('Failed to open link in iframe:', error);
894
- }
895
- }
896
- });
897
-
898
- return 'Iframe handler initialized';
899
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
900
  """
901
 
902
  with gr.Blocks(
903
  fill_height=True,
904
  fill_width=True,
905
  css=css,
906
- js=js,
907
  theme=gr.themes.Default(
908
  font=[gr.themes.GoogleFont("Inconsolata"), "Arial", "sans-serif"]
909
  ),
 
862
  cursor: progress;
863
  }
864
  """
865
+ head = f"""
866
+ <script defer src="https://www.gstatic.com/firebasejs/11.1.0/firebase-firestore.js"></script>
867
+ <script type="module">
868
+ // Import the functions you need from the SDKs you need
869
+ import {{ initializeApp }} from "https://www.gstatic.com/firebasejs/11.1.0/firebase-app.js";
870
+ import {{ getDatabase, ref, set }} from "https://www.gstatic.com/firebasejs/11.1.0/firebase-database.js";
871
+ // TODO: Add SDKs for Firebase products that you want to use
872
+ // https://firebase.google.com/docs/web/setup#available-libraries
873
+ console.log("Initializing Firebase");
874
+ // Your web app's Firebase configuration
875
+ // For Firebase JS SDK v7.20.0 and later, measurementId is optional
876
+ const firebaseConfig = {{
877
+ "apiKey": "AIzaSyDzhYytalbHOMaLJa8KXy6nvyTdp2PaY4Y",
878
+ "authDomain": "gfh-agora-video.firebaseapp.com",
879
+ "databaseURL": "https://gfh-agora-video.firebaseio.com",
880
+ "projectId": "gfh-agora-video",
881
+ "storageBucket": "gfh-agora-video.appspot.com",
882
+ "messagingSenderId": "229903401215",
883
+ "appId": "1:229903401215:web:f007bdf575a25063d04cca",
884
+ "measurementId": "G-ZT6PG5M8EV"
885
+ }};
886
+
887
+ // Initialize Firebase
888
+ const app = initializeApp(firebaseConfig);
889
+ const realtimeDB = getDatabase(app);
890
+ const rollAccount = "roll-prod-account";
891
+ const COLLECTIONS = {{
892
+ COLLAB_EDIT_LINK: "collab_link_handler",
893
+ }};
894
+
895
+ // Event listener for click
896
+ document.addEventListener('click', function (event) {{
897
+ var link = event.target.closest('a');
898
+ event.preventDefault();
899
+ if (link && link.href) {{
900
+
901
+ // Parse the URL to extract 'st' and 'et'
902
+ const url = new URL(link.href);
903
+ const startTime = url.searchParams.get('st');
904
+ const endTime = url.searchParams.get('et');
905
+ const userId = url.searchParams.get('uid') || "";
906
+
907
+ if (startTime || endTime) {{
908
+ let components = url.pathname.split("/");
909
+ let callId = components[2];
910
+ let recordingSessionId = components[3];
911
+
912
+ let data = {{
913
+ startTime: parseInt(startTime, 10),
914
+ endTime: parseInt(endTime, 10),
915
+ }};
916
+
917
+ console.log("Data to save:", data);
918
+
919
+ // Firebase reference
920
+ let reference = ref(
921
+ realtimeDB,
922
+ `${{rollAccount}}/${{COLLECTIONS.COLLAB_EDIT_LINK}}/${{userId}}/${{callId}}/${{recordingSessionId}}`
923
+ );
924
+
925
+ set(reference, data)
926
+ .then(() => {{
927
+ console.log("Data saved successfully:", data);
928
+ }})
929
+ .catch((error) => {{
930
+ console.error("Error saving data:", error);
931
+ }});
932
+ }}
933
+ }}
934
+ }});
935
+ </script>
936
  """
937
 
938
  with gr.Blocks(
939
  fill_height=True,
940
  fill_width=True,
941
  css=css,
942
+ head=head,
943
  theme=gr.themes.Default(
944
  font=[gr.themes.GoogleFont("Inconsolata"), "Arial", "sans-serif"]
945
  ),