Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -666,15 +666,8 @@ use_web_search = gr.Checkbox(label="Use Web Search", value=False)
|
|
666 |
|
667 |
custom_placeholder = "Ask a question (Note: You can toggle between Web Search and PDF Chat in Additional Inputs below)"
|
668 |
|
669 |
-
|
670 |
-
|
671 |
-
inputs=[
|
672 |
-
gr.Audio(sources="microphone", type="filepath")
|
673 |
-
],
|
674 |
-
outputs="text",
|
675 |
-
title="Speech to Text",
|
676 |
-
description="Speak your query, and it will be transcribed."
|
677 |
-
)
|
678 |
|
679 |
# Update the Gradio interface
|
680 |
with gr.Blocks() as demo:
|
@@ -682,56 +675,30 @@ with gr.Blocks() as demo:
|
|
682 |
|
683 |
with gr.Row():
|
684 |
with gr.Column(scale=1):
|
685 |
-
|
|
|
686 |
|
687 |
with gr.Column(scale=2):
|
688 |
-
chatbot = gr.
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
theme=gr.themes.Soft(
|
700 |
-
primary_hue="orange",
|
701 |
-
secondary_hue="amber",
|
702 |
-
neutral_hue="gray",
|
703 |
-
font=[gr.themes.GoogleFont("Exo"), "ui-sans-serif", "system-ui", "sans-serif"]
|
704 |
-
).set(
|
705 |
-
body_background_fill_dark="#0c0505",
|
706 |
-
block_background_fill_dark="#0c0505",
|
707 |
-
block_border_width="1px",
|
708 |
-
block_title_background_fill_dark="#1b0f0f",
|
709 |
-
input_background_fill_dark="#140b0b",
|
710 |
-
button_secondary_background_fill_dark="#140b0b",
|
711 |
-
border_color_accent_dark="#1b0f0f",
|
712 |
-
border_color_primary_dark="#1b0f0f",
|
713 |
-
background_fill_secondary_dark="#0c0505",
|
714 |
-
color_accent_soft_dark="transparent",
|
715 |
-
code_background_fill_dark="#140b0b"
|
716 |
-
),
|
717 |
-
css=css,
|
718 |
-
examples=[
|
719 |
-
["Tell me about the contents of the uploaded PDFs."],
|
720 |
-
["What are the main topics discussed in the documents?"],
|
721 |
-
["Can you summarize the key points from the PDFs?"],
|
722 |
-
["What's the latest news about artificial intelligence?"]
|
723 |
-
],
|
724 |
-
cache_examples=False,
|
725 |
-
analytics_enabled=False,
|
726 |
-
textbox=gr.Textbox(placeholder="Ask a question about the uploaded PDFs or any topic", container=False, scale=7),
|
727 |
-
chatbot=gr.Chatbot(
|
728 |
-
show_copy_button=True,
|
729 |
-
likeable=True,
|
730 |
-
layout="bubble",
|
731 |
-
height=400,
|
732 |
-
value=initial_conversation()
|
733 |
-
)
|
734 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
735 |
|
736 |
# Add file upload functionality
|
737 |
gr.Markdown("## Upload and Manage PDF Documents")
|
@@ -744,39 +711,49 @@ with gr.Blocks() as demo:
|
|
744 |
update_output = gr.Textbox(label="Update Status")
|
745 |
delete_button = gr.Button("Delete Selected Documents")
|
746 |
|
747 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
748 |
update_button.click(
|
749 |
update_vectors,
|
750 |
inputs=[file_input, parser_dropdown],
|
751 |
-
outputs=[update_output,
|
752 |
)
|
753 |
|
754 |
-
# Add the refresh button functionality
|
755 |
refresh_button.click(
|
756 |
refresh_documents,
|
757 |
inputs=[],
|
758 |
-
outputs=[
|
759 |
)
|
760 |
|
761 |
-
# Add the delete button functionality
|
762 |
delete_button.click(
|
763 |
delete_documents,
|
764 |
-
inputs=[
|
765 |
-
outputs=[update_output,
|
766 |
)
|
767 |
|
768 |
gr.Markdown(
|
769 |
"""
|
770 |
## How to use
|
771 |
-
1. Use the microphone to speak your query, or type
|
772 |
-
2.
|
773 |
-
3.
|
774 |
-
4. Select the
|
775 |
-
5.
|
776 |
6. Toggle "Use Web Search" to switch between PDF chat and web search.
|
777 |
7. Adjust Temperature and Number of API Calls to fine-tune the response generation.
|
778 |
-
8. Use the provided examples or ask your own questions.
|
779 |
"""
|
780 |
)
|
|
|
781 |
if __name__ == "__main__":
|
782 |
-
demo.launch(share=True)
|
|
|
666 |
|
667 |
custom_placeholder = "Ask a question (Note: You can toggle between Web Search and PDF Chat in Additional Inputs below)"
|
668 |
|
669 |
+
def update_textbox(transcription):
|
670 |
+
return gr.Textbox.update(value=transcription)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
671 |
|
672 |
# Update the Gradio interface
|
673 |
with gr.Blocks() as demo:
|
|
|
675 |
|
676 |
with gr.Row():
|
677 |
with gr.Column(scale=1):
|
678 |
+
audio_input = gr.Audio(sources="microphone", type="filepath", label="Speak your query")
|
679 |
+
transcribe_button = gr.Button("Transcribe")
|
680 |
|
681 |
with gr.Column(scale=2):
|
682 |
+
chatbot = gr.Chatbot(
|
683 |
+
show_copy_button=True,
|
684 |
+
likeable=True,
|
685 |
+
layout="bubble",
|
686 |
+
height=400,
|
687 |
+
value=initial_conversation()
|
688 |
+
)
|
689 |
+
query_textbox = gr.Textbox(
|
690 |
+
placeholder="Ask a question about the uploaded PDFs or any topic",
|
691 |
+
container=False,
|
692 |
+
scale=7
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
693 |
)
|
694 |
+
submit_button = gr.Button("Submit")
|
695 |
+
|
696 |
+
with gr.Accordion("⚙️ Parameters", open=False):
|
697 |
+
model = gr.Dropdown(choices=MODELS, label="Select Model", value=MODELS[3])
|
698 |
+
temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.2, step=0.1, label="Temperature")
|
699 |
+
num_calls = gr.Slider(minimum=1, maximum=5, value=1, step=1, label="Number of API Calls")
|
700 |
+
use_web_search = gr.Checkbox(label="Use Web Search", value=True)
|
701 |
+
document_selector = gr.CheckboxGroup(label="Select documents to query")
|
702 |
|
703 |
# Add file upload functionality
|
704 |
gr.Markdown("## Upload and Manage PDF Documents")
|
|
|
711 |
update_output = gr.Textbox(label="Update Status")
|
712 |
delete_button = gr.Button("Delete Selected Documents")
|
713 |
|
714 |
+
# Connect components
|
715 |
+
transcribe_button.click(
|
716 |
+
transcribe,
|
717 |
+
inputs=[audio_input],
|
718 |
+
outputs=[query_textbox]
|
719 |
+
)
|
720 |
+
|
721 |
+
submit_button.click(
|
722 |
+
respond,
|
723 |
+
inputs=[query_textbox, chatbot, model, temperature, num_calls, use_web_search, document_selector],
|
724 |
+
outputs=[chatbot]
|
725 |
+
)
|
726 |
+
|
727 |
update_button.click(
|
728 |
update_vectors,
|
729 |
inputs=[file_input, parser_dropdown],
|
730 |
+
outputs=[update_output, document_selector]
|
731 |
)
|
732 |
|
|
|
733 |
refresh_button.click(
|
734 |
refresh_documents,
|
735 |
inputs=[],
|
736 |
+
outputs=[document_selector]
|
737 |
)
|
738 |
|
|
|
739 |
delete_button.click(
|
740 |
delete_documents,
|
741 |
+
inputs=[document_selector],
|
742 |
+
outputs=[update_output, document_selector]
|
743 |
)
|
744 |
|
745 |
gr.Markdown(
|
746 |
"""
|
747 |
## How to use
|
748 |
+
1. Use the microphone to speak your query, then click "Transcribe", or type directly in the text box.
|
749 |
+
2. Click "Submit" to get a response from the AI.
|
750 |
+
3. Upload PDF documents using the file input at the bottom.
|
751 |
+
4. Select the PDF parser (pypdf or llamaparse) and click "Upload Document" to update the vector store.
|
752 |
+
5. Select the documents you want to query using the checkboxes.
|
753 |
6. Toggle "Use Web Search" to switch between PDF chat and web search.
|
754 |
7. Adjust Temperature and Number of API Calls to fine-tune the response generation.
|
|
|
755 |
"""
|
756 |
)
|
757 |
+
|
758 |
if __name__ == "__main__":
|
759 |
+
demo.launch(share=True)
|