Spaces:
Runtime error
Runtime error
Srinivasulu kethanaboina
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -3,8 +3,6 @@ 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 |
-
from llama_index.llms.huggingface import HuggingFaceInferenceAPI
|
7 |
-
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
|
8 |
import random
|
9 |
import datetime
|
10 |
|
@@ -89,6 +87,18 @@ def handle_query(query, cookies=None):
|
|
89 |
|
90 |
return response
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
# Define your Gradio chat interface function
|
93 |
def chat_interface(message, history):
|
94 |
cookies = {} # You might need to get cookies from the request in a real implementation
|
@@ -132,7 +142,10 @@ div.svelte-1rjryqp{display: none;}
|
|
132 |
div.progress-text.svelte-z7cif2.meta-text {display: none;}
|
133 |
'''
|
134 |
|
135 |
-
# Use Gradio Blocks to wrap components
|
136 |
-
|
|
|
|
|
137 |
|
138 |
# Launch the Gradio interface
|
|
|
|
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 |
|
|
|
87 |
|
88 |
return response
|
89 |
|
90 |
+
# Function to detect iframe and block chat history access
|
91 |
+
def detect_iframe():
|
92 |
+
iframe_script = '''
|
93 |
+
<script>
|
94 |
+
if (window != window.top) {
|
95 |
+
alert("Chat history access is disabled in iframes.");
|
96 |
+
document.getElementById('chat_history').style.display = 'none';
|
97 |
+
}
|
98 |
+
</script>
|
99 |
+
'''
|
100 |
+
return iframe_script
|
101 |
+
|
102 |
# Define your Gradio chat interface function
|
103 |
def chat_interface(message, history):
|
104 |
cookies = {} # You might need to get cookies from the request in a real implementation
|
|
|
142 |
div.progress-text.svelte-z7cif2.meta-text {display: none;}
|
143 |
'''
|
144 |
|
145 |
+
# Use Gradio Blocks to wrap components and add iframe detection
|
146 |
+
with gr.Blocks() as demo:
|
147 |
+
gr.HTML(detect_iframe())
|
148 |
+
chat = gr.ChatInterface(chat_interface, css=css, clear_btn=None, undo_btn=None, retry_btn=None)
|
149 |
|
150 |
# Launch the Gradio interface
|
151 |
+
demo.launch()
|