Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -28,7 +28,7 @@ import numpy as np
|
|
28 |
import threading
|
29 |
|
30 |
|
31 |
-
|
32 |
conversational_memory = ConversationBufferWindowMemory(
|
33 |
memory_key='chat_history',
|
34 |
k=10,
|
@@ -240,7 +240,11 @@ examples = [
|
|
240 |
["Who are the top players of the Crimson Tide?"],
|
241 |
["Where can I find a hamburger?"],
|
242 |
["What are some popular tourist attractions in Birmingham?"],
|
243 |
-
["What are some good clubs in Birmingham?"]
|
|
|
|
|
|
|
|
|
244 |
]
|
245 |
|
246 |
# Function to insert the prompt into the textbox when clicked
|
@@ -339,29 +343,28 @@ with gr.Blocks(theme="rawrsor1/Everforest") as demo:
|
|
339 |
with gr.Row():
|
340 |
with gr.Column():
|
341 |
gr.Markdown("<h1 style='color: red;'>Example Prompts</h1>", elem_id="Example-Prompts")
|
342 |
-
gr.Examples(examples=examples, fn=insert_prompt, inputs=question_input, outputs=question_input)
|
343 |
|
344 |
# Define interactions
|
345 |
# Define interactions for clicking the button
|
346 |
-
get_response_btn.click(fn=add_message, inputs=[chatbot, question_input], outputs=[chatbot, question_input])\
|
347 |
-
.then(fn=chat_with_bot, inputs=[chatbot], outputs=chatbot)
|
348 |
# Define interaction for hitting the Enter key
|
349 |
-
question_input.submit(fn=add_message, inputs=[chatbot, question_input], outputs=[chatbot, question_input])\
|
350 |
-
.then(fn=chat_with_bot, inputs=[chatbot], outputs=chatbot)
|
351 |
|
352 |
# Speech-to-Text functionality
|
353 |
state = gr.State()
|
354 |
-
audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, question_input])
|
355 |
|
356 |
|
357 |
-
generate_audio_btn.click(fn=generate_audio_from_last_response, inputs=chatbot, outputs=audio_output)
|
358 |
-
clean_btn.click(fn=clear_fields, inputs=[], outputs=[chatbot, question_input, audio_output])
|
359 |
|
360 |
|
361 |
# Clear state interaction
|
362 |
-
clear_state_btn.click(fn=clear_transcription_state, outputs=[question_input, state])
|
363 |
|
364 |
|
365 |
# Launch the Gradio interface
|
366 |
-
demo.launch(show_error=True)
|
367 |
-
|
|
|
28 |
import threading
|
29 |
|
30 |
|
31 |
+
#code for history
|
32 |
conversational_memory = ConversationBufferWindowMemory(
|
33 |
memory_key='chat_history',
|
34 |
k=10,
|
|
|
240 |
["Who are the top players of the Crimson Tide?"],
|
241 |
["Where can I find a hamburger?"],
|
242 |
["What are some popular tourist attractions in Birmingham?"],
|
243 |
+
["What are some good clubs in Birmingham?"],
|
244 |
+
["Is there a farmer's market or craft fair in Birmingham, Alabama?"],
|
245 |
+
["Are there any special holiday events or parades in Birmingham, Alabama, during December?"],
|
246 |
+
["What are the best places to enjoy live music in Birmingham, Alabama?"]
|
247 |
+
|
248 |
]
|
249 |
|
250 |
# Function to insert the prompt into the textbox when clicked
|
|
|
343 |
with gr.Row():
|
344 |
with gr.Column():
|
345 |
gr.Markdown("<h1 style='color: red;'>Example Prompts</h1>", elem_id="Example-Prompts")
|
346 |
+
gr.Examples(examples=examples, fn=insert_prompt, inputs=question_input, outputs=question_input,api_name="api_insert_example")
|
347 |
|
348 |
# Define interactions
|
349 |
# Define interactions for clicking the button
|
350 |
+
get_response_btn.click(fn=add_message, inputs=[chatbot, question_input], outputs=[chatbot, question_input],api_name="api_add_message_on_button_click")\
|
351 |
+
.then(fn=chat_with_bot, inputs=[chatbot], outputs=chatbot,api_name="api_get response_on_button")
|
352 |
# Define interaction for hitting the Enter key
|
353 |
+
question_input.submit(fn=add_message, inputs=[chatbot, question_input], outputs=[chatbot, question_input],api_name="api_add_message_on _enter")\
|
354 |
+
.then(fn=chat_with_bot, inputs=[chatbot], outputs=chatbot,api_name="api_get response_on_enter")
|
355 |
|
356 |
# Speech-to-Text functionality
|
357 |
state = gr.State()
|
358 |
+
audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, question_input],api_name="api_voice_to_text")
|
359 |
|
360 |
|
361 |
+
generate_audio_btn.click(fn=generate_audio_from_last_response, inputs=chatbot, outputs=audio_output,api_name="api_generate_text_to_audio")
|
362 |
+
clean_btn.click(fn=clear_fields, inputs=[], outputs=[chatbot, question_input, audio_output],api_name="api_clear_textbox")
|
363 |
|
364 |
|
365 |
# Clear state interaction
|
366 |
+
clear_state_btn.click(fn=clear_transcription_state, outputs=[question_input, state],api_name="api_clean_state_transcription")
|
367 |
|
368 |
|
369 |
# Launch the Gradio interface
|
370 |
+
demo.launch(show_error=True)
|
|