Spaces:
Paused
Paused
auth
Browse files
app.py
CHANGED
@@ -109,6 +109,19 @@ def is_authenticated():
|
|
109 |
|
110 |
# Function to retrieve answer using the RAG system
|
111 |
@spaces.GPU(duration=60)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
# Gradio app with OAuth integration
|
113 |
def chat_interface():
|
114 |
global access_token
|
@@ -117,19 +130,6 @@ def chat_interface():
|
|
117 |
if not is_authenticated():
|
118 |
auth_url = get_auth_url()
|
119 |
return gr.Markdown(f"Please [log in]({auth_url}) to use the chatbot.")
|
120 |
-
|
121 |
-
def test_rag(query):
|
122 |
-
books_retriever = books_db_client_retriever.run(query)
|
123 |
-
|
124 |
-
# Extract the relevant answer using regex
|
125 |
-
corrected_text_match = re.search(r"Helpful Answer:(.*)", books_retriever, re.DOTALL)
|
126 |
-
|
127 |
-
if corrected_text_match:
|
128 |
-
corrected_text_books = corrected_text_match.group(1).strip()
|
129 |
-
else:
|
130 |
-
corrected_text_books = "No helpful answer found."
|
131 |
-
|
132 |
-
return corrected_text_books
|
133 |
|
134 |
# Gradio chatbot interface
|
135 |
def chat(query, history=None):
|
@@ -137,7 +137,7 @@ def chat_interface():
|
|
137 |
history = []
|
138 |
if query:
|
139 |
# Chatbot logic here
|
140 |
-
answer =
|
141 |
history.append((query, answer))
|
142 |
return history, "" # Clear input after submission
|
143 |
|
|
|
109 |
|
110 |
# Function to retrieve answer using the RAG system
|
111 |
@spaces.GPU(duration=60)
|
112 |
+
def test_rag(query):
|
113 |
+
books_retriever = books_db_client_retriever.run(query)
|
114 |
+
|
115 |
+
# Extract the relevant answer using regex
|
116 |
+
corrected_text_match = re.search(r"Helpful Answer:(.*)", books_retriever, re.DOTALL)
|
117 |
+
|
118 |
+
if corrected_text_match:
|
119 |
+
corrected_text_books = corrected_text_match.group(1).strip()
|
120 |
+
else:
|
121 |
+
corrected_text_books = "No helpful answer found."
|
122 |
+
|
123 |
+
return corrected_text_books
|
124 |
+
|
125 |
# Gradio app with OAuth integration
|
126 |
def chat_interface():
|
127 |
global access_token
|
|
|
130 |
if not is_authenticated():
|
131 |
auth_url = get_auth_url()
|
132 |
return gr.Markdown(f"Please [log in]({auth_url}) to use the chatbot.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
|
134 |
# Gradio chatbot interface
|
135 |
def chat(query, history=None):
|
|
|
137 |
history = []
|
138 |
if query:
|
139 |
# Chatbot logic here
|
140 |
+
answer = test_rag(query)
|
141 |
history.append((query, answer))
|
142 |
return history, "" # Clear input after submission
|
143 |
|