Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -17,6 +17,15 @@ from langchain_core.runnables import (
|
|
17 |
from langchain_core.prompts.prompt import PromptTemplate
|
18 |
import requests
|
19 |
import tempfile
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# Setup Neo4j
|
22 |
graph = Neo4jGraph(
|
@@ -116,9 +125,12 @@ _search_query = RunnableBranch(
|
|
116 |
)
|
117 |
|
118 |
# Define the QA prompt template
|
119 |
-
template = """As an expert concierge known for being helpful and a renowned guide for Birmingham, Alabama,
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
122 |
{context}
|
123 |
Question: {question}
|
124 |
Helpful Answer:"""
|
@@ -183,12 +195,26 @@ def generate_audio_elevenlabs(text):
|
|
183 |
|
184 |
# Create the Gradio Blocks interface
|
185 |
with gr.Blocks() as demo:
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
|
193 |
get_response_btn.click(fn=get_response, inputs=question_input, outputs=response_output)
|
194 |
generate_audio_btn.click(fn=generate_audio_elevenlabs, inputs=response_output, outputs=audio_output)
|
|
|
17 |
from langchain_core.prompts.prompt import PromptTemplate
|
18 |
import requests
|
19 |
import tempfile
|
20 |
+
from langchain_core.memory import ConversationBufferWindowMemory
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
+
conversational_memory = ConversationBufferWindowMemory(
|
25 |
+
memory_key='chat_history',
|
26 |
+
k=10,
|
27 |
+
return_messages=True
|
28 |
+
)
|
29 |
|
30 |
# Setup Neo4j
|
31 |
graph = Neo4jGraph(
|
|
|
125 |
)
|
126 |
|
127 |
# Define the QA prompt template
|
128 |
+
template = """As an expert concierge known for being helpful and a renowned guide for Birmingham, Alabama,
|
129 |
+
I assist visitors in discovering the best that the city has to offer. I also assist the visitors about various sports and activities.
|
130 |
+
I am well-equipped to provide valuable insights and recommendations.
|
131 |
+
I draw upon my extensive knowledge of the area, including perennial events and historical context.
|
132 |
+
In light of this, how can I assist you today? Feel free to ask any questions or seek recommendations for your day in Birmingham. If there's anything specific you'd like to know or experience,
|
133 |
+
please share, and I'll be glad to help. Remember, keep the response precise short, crisp, and accurate response and don't greet.
|
134 |
{context}
|
135 |
Question: {question}
|
136 |
Helpful Answer:"""
|
|
|
195 |
|
196 |
# Create the Gradio Blocks interface
|
197 |
with gr.Blocks() as demo:
|
198 |
+
with gr.Row():
|
199 |
+
with gr.Column():
|
200 |
+
|
201 |
+
response_output = gr.Textbox(
|
202 |
+
label="Response",
|
203 |
+
placeholder="The response will appear here...",
|
204 |
+
interactive=False,
|
205 |
+
lines=10, # Sets the number of visible lines
|
206 |
+
max_lines=20 # Allows for a larger display area if needed
|
207 |
+
)
|
208 |
+
question_input = gr.Textbox(label="Ask a Question", placeholder="Type your question here...")
|
209 |
+
with gr.Column():
|
210 |
+
audio_output = gr.Audio(label="Audio", type="filepath", interactive=False)
|
211 |
+
with gr.Row():
|
212 |
+
with gr.Column():
|
213 |
+
get_response_btn = gr.Button("Get Response")
|
214 |
+
with gr.Column():
|
215 |
+
generate_audio_btn = gr.Button("Generate Audio")
|
216 |
+
with gr.Column():
|
217 |
+
clean_btn = gr.Button("Clean")
|
218 |
|
219 |
get_response_btn.click(fn=get_response, inputs=question_input, outputs=response_output)
|
220 |
generate_audio_btn.click(fn=generate_audio_elevenlabs, inputs=response_output, outputs=audio_output)
|