Pijush2023 commited on
Commit
f8bd341
·
verified ·
1 Parent(s): cbfa3fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -111
app.py CHANGED
@@ -1635,55 +1635,58 @@ files_list = [
1635
  ]
1636
 
1637
 
 
1638
 
1639
 
1640
-
1641
- # with gr.Blocks(theme='gradio/soft') as demo:
1642
 
1643
 
1644
- # with gr.Row():
1645
- # with gr.Column():
1646
- # state = gr.State()
1647
 
1648
- # chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
1649
- # choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational",interactive=False,visible=False)
1650
- # retrieval_mode = gr.Radio(label="Retrieval Mode", choices=["VDB", "KGF"], value="VDB",interactive=False,visible=False)
1651
- # model_choice = gr.Dropdown(label="Choose Model", choices=["LM-2"], value="LM-2")
 
 
 
1652
 
1653
- # # Link the dropdown change to handle_model_choice_change
1654
- # model_choice.change(fn=handle_model_choice_change, inputs=model_choice, outputs=[retrieval_mode, choice, choice])
1655
 
1656
- # # gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
1657
 
1658
- # chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
1659
- # tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta"], value="Alpha")
1660
 
1661
- # retriever_button = gr.Button("Retriever")
1662
 
1663
- # clear_button = gr.Button("Clear")
1664
- # clear_button.click(lambda: [None, None], outputs=[chat_input, state])
1665
 
1666
- # # gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
1667
- # # location_output = gr.HTML()
1668
- # audio_output = gr.Audio(interactive=False, autoplay=True)
1669
 
1670
- # def stop_audio():
1671
- # audio_output.stop()
1672
- # return None
1673
 
1674
 
1675
 
1676
 
1677
 
1678
- # retriever_sequence = (
1679
- # retriever_button.click(fn=stop_audio, inputs=[], outputs=[audio_output], api_name="api_stop_audio_recording")
1680
- # .then(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input], api_name="api_addprompt_chathistory")
1681
- # # First, generate the bot response
1682
- # .then(fn=generate_bot_response, inputs=[chatbot, choice, retrieval_mode, model_choice], outputs=[chatbot], api_name="api_generate_bot_response")
1683
- # # Then, generate the TTS response based on the bot's response
1684
- # .then(fn=generate_tts_response, inputs=[chatbot, tts_choice], outputs=[audio_output], api_name="api_generate_tts_response")
1685
- # .then(fn=clear_textbox, inputs=[], outputs=[chat_input], api_name="api_clear_textbox")
1686
- # )
1687
 
1688
 
1689
 
@@ -1692,17 +1695,17 @@ files_list = [
1692
 
1693
 
1694
 
1695
- # chat_input.submit(fn=stop_audio, inputs=[], outputs=[audio_output], api_name="api_stop_audio_recording").then(
1696
- # fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input], api_name="api_addprompt_chathistory"
1697
- # ).then(
1698
- # # First, generate the bot response
1699
- # fn=generate_bot_response, inputs=[chatbot, choice, retrieval_mode, model_choice], outputs=[chatbot], api_name="api_generate_bot_response"
1700
- # ).then(
1701
- # # Then, generate the TTS response based on the bot's response
1702
- # fn=generate_tts_response, inputs=[chatbot, tts_choice], outputs=[audio_output], api_name="api_generate_tts_response"
1703
- # ).then(
1704
- # fn=clear_textbox, inputs=[], outputs=[chat_input], api_name="api_clear_textbox"
1705
- # )
1706
 
1707
 
1708
 
@@ -1710,31 +1713,31 @@ files_list = [
1710
 
1711
 
1712
 
1713
- # audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy', every=0.1)
1714
- # audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="api_voice_to_text")
1715
 
1716
- # # gr.Markdown("<h1 style='color: red;'>Example Prompts</h1>", elem_id="Example-Prompts")
1717
- # # gr.Examples(examples=examples, fn=insert_prompt,inputs=chat_input, outputs=chat_input)
1718
 
1719
- # # with gr.Column():
1720
- # # weather_output = gr.HTML(value=fetch_local_weather())
1721
- # # news_output = gr.HTML(value=fetch_local_news())
1722
- # # events_output = gr.HTML(value=fetch_local_events())
1723
 
1724
- # # with gr.Column():
1725
 
1726
 
1727
- # # # Call update_images during the initial load to display images when the interface appears
1728
- # # initial_images = update_images()
1729
 
1730
- # # # Displaying the images generated using Flux API directly
1731
- # # image_output_1 = gr.Image(value=initial_images[0], label="Image 1", elem_id="flux_image_1", width=400, height=400)
1732
- # # image_output_2 = gr.Image(value=initial_images[1], label="Image 2", elem_id="flux_image_2", width=400, height=400)
1733
- # # image_output_3 = gr.Image(value=initial_images[2], label="Image 3", elem_id="flux_image_3", width=400, height=400)
1734
 
1735
- # # # Refresh button to update images
1736
- # # refresh_button = gr.Button("Refresh Images")
1737
- # # refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
1738
 
1739
 
1740
 
@@ -1742,59 +1745,11 @@ files_list = [
1742
 
1743
 
1744
 
1745
- # demo.queue()
1746
- # demo.launch(show_error=True)
1747
-
1748
-
1749
- with gr.Blocks(theme='gradio/soft') as demo:
1750
- with gr.Row():
1751
- with gr.Column():
1752
- state = gr.State()
1753
-
1754
- # File dropdown
1755
- file_dropdown = gr.Dropdown(label="Select Document", choices=files_list, value=None)
1756
-
1757
- chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
1758
- choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational",interactive=False,visible=False)
1759
- retrieval_mode = gr.Radio(label="Retrieval Mode", choices=["VDB", "KGF"], value="VDB",interactive=False,visible=False)
1760
- model_choice = gr.Dropdown(label="Choose Model", choices=["LM-2"], value="LM-2")
1761
-
1762
- # Link the dropdown change to handle_model_choice_change
1763
- model_choice.change(fn=handle_model_choice_change, inputs=model_choice, outputs=[retrieval_mode, choice, choice])
1764
-
1765
- chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
1766
- tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta"], value="Alpha")
1767
- retriever_button = gr.Button("Retriever")
1768
- clear_button = gr.Button("Clear")
1769
- clear_button.click(lambda: [None, None], outputs=[chat_input, state])
1770
-
1771
- audio_output = gr.Audio(interactive=False, autoplay=True)
1772
-
1773
- def stop_audio():
1774
- audio_output.stop()
1775
- return None
1776
 
1777
- # Modify retriever sequence to include file selection
1778
- retriever_sequence = (
1779
- retriever_button.click(fn=stop_audio, inputs=[], outputs=[audio_output], api_name="api_stop_audio_recording")
1780
- .then(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input], api_name="api_addprompt_chathistory")
1781
- # Pass the selected file to the bot response generation
1782
- .then(fn=generate_answer, inputs=[chatbot, choice, retrieval_mode, model_choice, file_dropdown], outputs=[chatbot], api_name="api_generate_bot_response_with_file")
1783
- .then(fn=generate_tts_response, inputs=[chatbot, tts_choice], outputs=[audio_output], api_name="api_generate_tts_response")
1784
- .then(fn=clear_textbox, inputs=[], outputs=[chat_input], api_name="api_clear_textbox")
1785
- )
1786
 
1787
- chat_input.submit(fn=stop_audio, inputs=[], outputs=[audio_output], api_name="api_stop_audio_recording").then(
1788
- fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input], api_name="api_addprompt_chathistory"
1789
- ).then(
1790
- fn=generate_answer, inputs=[chatbot, choice, retrieval_mode, model_choice, file_dropdown], outputs=[chatbot], api_name="api_generate_bot_response_with_file"
1791
- ).then(
1792
- fn=generate_tts_response, inputs=[chatbot, tts_choice], outputs=[audio_output], api_name="api_generate_tts_response"
1793
- ).then(
1794
- fn=clear_textbox, inputs=[], outputs=[chat_input], api_name="api_clear_textbox"
1795
- )
1796
 
1797
- demo.launch()
1798
 
1799
 
1800
 
 
1635
  ]
1636
 
1637
 
1638
+ file_dropdown = gr.Dropdown(label="Select Document", choices=files_list, value=None)
1639
 
1640
 
1641
+ with gr.Blocks(theme='gradio/soft') as demo:
 
1642
 
1643
 
1644
+ with gr.Row():
1645
+ with gr.Column():
1646
+ state = gr.State()
1647
 
1648
+ # File dropdown
1649
+ file_dropdown = gr.Dropdown(label="Select Document", choices=files_list, value=None)
1650
+
1651
+ chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
1652
+ choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational",interactive=False,visible=False)
1653
+ retrieval_mode = gr.Radio(label="Retrieval Mode", choices=["VDB", "KGF"], value="VDB",interactive=False,visible=False)
1654
+ model_choice = gr.Dropdown(label="Choose Model", choices=["LM-2"], value="LM-2")
1655
 
1656
+ # Link the dropdown change to handle_model_choice_change
1657
+ model_choice.change(fn=handle_model_choice_change, inputs=model_choice, outputs=[retrieval_mode, choice, choice])
1658
 
1659
+ # gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
1660
 
1661
+ chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
1662
+ tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta"], value="Alpha")
1663
 
1664
+ retriever_button = gr.Button("Retriever")
1665
 
1666
+ clear_button = gr.Button("Clear")
1667
+ clear_button.click(lambda: [None, None], outputs=[chat_input, state])
1668
 
1669
+ # gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
1670
+ # location_output = gr.HTML()
1671
+ audio_output = gr.Audio(interactive=False, autoplay=True)
1672
 
1673
+ def stop_audio():
1674
+ audio_output.stop()
1675
+ return None
1676
 
1677
 
1678
 
1679
 
1680
 
1681
+ retriever_sequence = (
1682
+ retriever_button.click(fn=stop_audio, inputs=[], outputs=[audio_output], api_name="api_stop_audio_recording")
1683
+ .then(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input], api_name="api_addprompt_chathistory")
1684
+ # First, generate the bot response
1685
+ .then(fn=generate_bot_response, inputs=[chatbot, choice, retrieval_mode, model_choice], outputs=[chatbot], api_name="api_generate_bot_response")
1686
+ # Then, generate the TTS response based on the bot's response
1687
+ .then(fn=generate_tts_response, inputs=[chatbot, tts_choice], outputs=[audio_output], api_name="api_generate_tts_response")
1688
+ .then(fn=clear_textbox, inputs=[], outputs=[chat_input], api_name="api_clear_textbox")
1689
+ )
1690
 
1691
 
1692
 
 
1695
 
1696
 
1697
 
1698
+ chat_input.submit(fn=stop_audio, inputs=[], outputs=[audio_output], api_name="api_stop_audio_recording").then(
1699
+ fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input], api_name="api_addprompt_chathistory"
1700
+ ).then(
1701
+ # First, generate the bot response
1702
+ fn=generate_bot_response, inputs=[chatbot, choice, retrieval_mode, model_choice], outputs=[chatbot], api_name="api_generate_bot_response"
1703
+ ).then(
1704
+ # Then, generate the TTS response based on the bot's response
1705
+ fn=generate_tts_response, inputs=[chatbot, tts_choice], outputs=[audio_output], api_name="api_generate_tts_response"
1706
+ ).then(
1707
+ fn=clear_textbox, inputs=[], outputs=[chat_input], api_name="api_clear_textbox"
1708
+ )
1709
 
1710
 
1711
 
 
1713
 
1714
 
1715
 
1716
+ audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy', every=0.1)
1717
+ audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="api_voice_to_text")
1718
 
1719
+ # gr.Markdown("<h1 style='color: red;'>Example Prompts</h1>", elem_id="Example-Prompts")
1720
+ # gr.Examples(examples=examples, fn=insert_prompt,inputs=chat_input, outputs=chat_input)
1721
 
1722
+ # with gr.Column():
1723
+ # weather_output = gr.HTML(value=fetch_local_weather())
1724
+ # news_output = gr.HTML(value=fetch_local_news())
1725
+ # events_output = gr.HTML(value=fetch_local_events())
1726
 
1727
+ # with gr.Column():
1728
 
1729
 
1730
+ # # Call update_images during the initial load to display images when the interface appears
1731
+ # initial_images = update_images()
1732
 
1733
+ # # Displaying the images generated using Flux API directly
1734
+ # image_output_1 = gr.Image(value=initial_images[0], label="Image 1", elem_id="flux_image_1", width=400, height=400)
1735
+ # image_output_2 = gr.Image(value=initial_images[1], label="Image 2", elem_id="flux_image_2", width=400, height=400)
1736
+ # image_output_3 = gr.Image(value=initial_images[2], label="Image 3", elem_id="flux_image_3", width=400, height=400)
1737
 
1738
+ # # Refresh button to update images
1739
+ # refresh_button = gr.Button("Refresh Images")
1740
+ # refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
1741
 
1742
 
1743
 
 
1745
 
1746
 
1747
 
1748
+ demo.queue()
1749
+ demo.launch(show_error=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1750
 
 
 
 
 
 
 
 
 
 
1751
 
 
 
 
 
 
 
 
 
 
1752
 
 
1753
 
1754
 
1755