Srinivasulu kethanaboina commited on
Commit
6cd1447
·
verified ·
1 Parent(s): 592600b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -17
app.py CHANGED
@@ -3,10 +3,11 @@ import os
3
  from http.cookies import SimpleCookie
4
  from dotenv import load_dotenv
5
  from llama_index.core import StorageContext, load_index_from_storage, VectorStoreIndex, SimpleDirectoryReader, ChatPromptTemplate, Settings
6
- import random
7
- import datetime
8
  from llama_index.llms.huggingface import HuggingFaceInferenceAPI
9
  from llama_index.embeddings.huggingface import HuggingFaceEmbedding
 
 
 
10
 
11
  # Load environment variables
12
  load_dotenv()
@@ -89,17 +90,13 @@ def handle_query(query, cookies=None):
89
 
90
  return response
91
 
92
- # Function to detect iframe and block chat history access
93
- def detect_iframe():
94
- iframe_script = '''
95
- <script>
96
- if (window != window.top) {
97
- alert("Chat history access is disabled in iframes.");
98
- document.getElementById('chat_history').style.display = 'none';
99
- }
100
- </script>
101
- '''
102
- return iframe_script
103
 
104
  # Define your Gradio chat interface function
105
  def chat_interface(message, history):
@@ -144,10 +141,15 @@ div.svelte-1rjryqp{display: none;}
144
  div.progress-text.svelte-z7cif2.meta-text {display: none;}
145
  '''
146
 
147
- # Use Gradio Blocks to wrap components and add iframe detection
148
- with gr.Blocks() as demo:
149
- gr.HTML(detect_iframe())
150
- chat = gr.ChatInterface(chat_interface, css=css, clear_btn=None, undo_btn=None, retry_btn=None)
 
 
 
 
 
151
 
152
  # Launch the Gradio interface
153
  demo.launch()
 
3
  from http.cookies import SimpleCookie
4
  from dotenv import load_dotenv
5
  from llama_index.core import StorageContext, load_index_from_storage, VectorStoreIndex, SimpleDirectoryReader, ChatPromptTemplate, Settings
 
 
6
  from llama_index.llms.huggingface import HuggingFaceInferenceAPI
7
  from llama_index.embeddings.huggingface import HuggingFaceEmbedding
8
+ import random
9
+ import datetime
10
+ import webbrowser # To handle the redirect
11
 
12
  # Load environment variables
13
  load_dotenv()
 
90
 
91
  return response
92
 
93
+ # Define the button click function
94
+ def retrieve_history_and_redirect():
95
+ # Here you can retrieve the chat history if necessary
96
+ # You can return it, log it, or perform any necessary action
97
+ # Redirect to the specified page
98
+ webbrowser.open("https://redfernstech.com/chat-bot-test")
99
+ return "Redirecting..."
 
 
 
 
100
 
101
  # Define your Gradio chat interface function
102
  def chat_interface(message, history):
 
141
  div.progress-text.svelte-z7cif2.meta-text {display: none;}
142
  '''
143
 
144
+ # Use Gradio Blocks to wrap components
145
+ with gr.Blocks(css=css) as demo:
146
+ chat = gr.ChatInterface(chat_interface, clear_btn=None, undo_btn=None, retry_btn=None)
147
+
148
+ # Button to retrieve history and redirect
149
+ redirect_button = gr.Button("Retrieve History & Redirect")
150
+
151
+ # Connect the button with the function
152
+ redirect_button.click(fn=retrieve_history_and_redirect, inputs=[], outputs=chat)
153
 
154
  # Launch the Gradio interface
155
  demo.launch()