Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1481,123 +1481,61 @@ files_list = [
|
|
1481 |
"178041_000197000852_V2.pdf"
|
1482 |
]
|
1483 |
|
1484 |
-
def generate_table_html(responses):
|
1485 |
-
# HTML structure for the table
|
1486 |
-
table_html = """
|
1487 |
-
<h2>Top 3 Responses</h2>
|
1488 |
-
<table style="width:100%; border-collapse: collapse; border: 1px solid black;">
|
1489 |
-
<tr>
|
1490 |
-
<th style="border: 1px solid black; padding: 8px;">Container (Document Name)</th>
|
1491 |
-
<th style="border: 1px solid black; padding: 8px;">Page Number</th>
|
1492 |
-
<th style="border: 1px solid black; padding: 8px;">Response</th>
|
1493 |
-
<th style="border: 1px solid black; padding: 8px;">Metadata</th>
|
1494 |
-
</tr>
|
1495 |
-
"""
|
1496 |
|
1497 |
-
for response in responses[:3]: # Limiting to top 3 responses
|
1498 |
-
document_name = response.get("document_name", "Unknown")
|
1499 |
-
page_number = response.get("page_number", "Unknown")
|
1500 |
-
content = response.get("content", "No content available")
|
1501 |
-
metadata = response.get("metadata", "No metadata available")
|
1502 |
-
|
1503 |
-
# Adding rows dynamically to the table
|
1504 |
-
table_html += f"""
|
1505 |
-
<tr>
|
1506 |
-
<td style="border: 1px solid black; padding: 8px;">{document_name}</td>
|
1507 |
-
<td style="border: 1px solid black; padding: 8px;">{page_number}</td>
|
1508 |
-
<td style="border: 1px solid black; padding: 8px;">{content}</td>
|
1509 |
-
<td style="border: 1px solid black; padding: 8px;">{metadata}</td>
|
1510 |
-
</tr>
|
1511 |
-
"""
|
1512 |
|
1513 |
-
# Closing the table
|
1514 |
-
table_html += "</table>"
|
1515 |
-
return table_html
|
1516 |
|
1517 |
|
1518 |
-
def generate_bot_response_with_table(history, choice, retrieval_mode, model_choice):
|
1519 |
-
if not history:
|
1520 |
-
return
|
1521 |
|
1522 |
-
# Select the model
|
1523 |
-
selected_model = chat_model if model_choice == "LM-1" else (chat_model1 if model_choice == "LM-3" else phi_pipe)
|
1524 |
|
1525 |
-
|
1526 |
-
|
1527 |
-
# Extract relevant information from the response to create table content
|
1528 |
-
responses = []
|
1529 |
-
for doc in response[:3]: # Limiting to top 3 results
|
1530 |
-
responses.append({
|
1531 |
-
"document_name": doc.get("document_name", "Unknown"),
|
1532 |
-
"page_number": doc.get("page_number", "Unknown"),
|
1533 |
-
"content": doc.get("content", "No content available"),
|
1534 |
-
"metadata": doc.get("metadata", "No metadata available")
|
1535 |
-
})
|
1536 |
-
|
1537 |
-
# Generate the HTML for the table
|
1538 |
-
table_html = generate_table_html(responses)
|
1539 |
-
|
1540 |
-
history[-1][1] = ""
|
1541 |
-
|
1542 |
-
for character in response:
|
1543 |
-
history[-1][1] += character
|
1544 |
-
yield history, table_html # Yielding history and table HTML for real-time updates
|
1545 |
-
|
1546 |
-
yield history, table_html # Final yield with the complete response and table
|
1547 |
-
|
1548 |
-
|
1549 |
-
|
1550 |
-
|
1551 |
-
|
1552 |
-
# with gr.Blocks(theme='gradio/soft') as demo:
|
1553 |
|
1554 |
|
1555 |
-
|
1556 |
-
|
1557 |
-
|
1558 |
|
1559 |
-
#
|
1560 |
-
#
|
1561 |
|
1562 |
-
|
1563 |
-
|
1564 |
-
|
1565 |
-
|
1566 |
|
1567 |
-
#
|
1568 |
-
|
1569 |
|
1570 |
-
#
|
1571 |
|
1572 |
-
|
1573 |
-
|
1574 |
|
1575 |
-
|
1576 |
|
1577 |
-
|
1578 |
-
|
1579 |
|
1580 |
-
#
|
1581 |
-
#
|
1582 |
-
|
1583 |
|
1584 |
-
|
1585 |
-
|
1586 |
-
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 |
|
1592 |
-
|
1593 |
-
|
1594 |
-
|
1595 |
-
#
|
1596 |
-
|
1597 |
-
#
|
1598 |
-
|
1599 |
-
|
1600 |
-
|
1601 |
|
1602 |
|
1603 |
|
@@ -1606,17 +1544,17 @@ def generate_bot_response_with_table(history, choice, retrieval_mode, model_choi
|
|
1606 |
|
1607 |
|
1608 |
|
1609 |
-
|
1610 |
-
|
1611 |
-
|
1612 |
-
#
|
1613 |
-
|
1614 |
-
|
1615 |
-
#
|
1616 |
-
|
1617 |
-
|
1618 |
-
|
1619 |
-
|
1620 |
|
1621 |
|
1622 |
|
@@ -1624,31 +1562,31 @@ def generate_bot_response_with_table(history, choice, retrieval_mode, model_choi
|
|
1624 |
|
1625 |
|
1626 |
|
1627 |
-
|
1628 |
-
|
1629 |
|
1630 |
-
#
|
1631 |
-
#
|
1632 |
|
1633 |
-
#
|
1634 |
-
#
|
1635 |
-
#
|
1636 |
-
#
|
1637 |
|
1638 |
-
#
|
1639 |
|
1640 |
|
1641 |
-
#
|
1642 |
-
#
|
1643 |
|
1644 |
-
#
|
1645 |
-
#
|
1646 |
-
#
|
1647 |
-
#
|
1648 |
|
1649 |
-
#
|
1650 |
-
#
|
1651 |
-
#
|
1652 |
|
1653 |
|
1654 |
|
@@ -1656,62 +1594,11 @@ def generate_bot_response_with_table(history, choice, retrieval_mode, model_choi
|
|
1656 |
|
1657 |
|
1658 |
|
1659 |
-
# demo.queue()
|
1660 |
-
# demo.launch(show_error=True)
|
1661 |
-
|
1662 |
-
with gr.Blocks(theme='gradio/soft') as demo:
|
1663 |
-
|
1664 |
-
with gr.Row():
|
1665 |
-
with gr.Column():
|
1666 |
-
state = gr.State()
|
1667 |
-
|
1668 |
-
chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
|
1669 |
-
choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational",interactive=False,visible=False)
|
1670 |
-
retrieval_mode = gr.Radio(label="Retrieval Mode", choices=["VDB", "KGF"], value="VDB",interactive=False,visible=False)
|
1671 |
-
model_choice = gr.Dropdown(label="Choose Model", choices=["LM-2"], value="LM-2")
|
1672 |
-
|
1673 |
-
# Link the dropdown change to handle_model_choice_change
|
1674 |
-
model_choice.change(fn=handle_model_choice_change, inputs=model_choice, outputs=[retrieval_mode, choice, choice])
|
1675 |
-
|
1676 |
-
chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
|
1677 |
-
tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta"], value="Alpha")
|
1678 |
-
|
1679 |
-
retriever_button = gr.Button("Retriever")
|
1680 |
-
clear_button = gr.Button("Clear")
|
1681 |
-
clear_button.click(lambda: [None, None], outputs=[chat_input, state])
|
1682 |
-
|
1683 |
-
def stop_audio():
|
1684 |
-
audio_output.stop()
|
1685 |
-
return None
|
1686 |
-
|
1687 |
-
# HTML component for displaying the dynamic table
|
1688 |
-
table_output = gr.HTML()
|
1689 |
-
|
1690 |
-
# Audio output for TTS
|
1691 |
-
audio_output = gr.Audio(interactive=False, autoplay=True)
|
1692 |
-
|
1693 |
-
# Retriever sequence
|
1694 |
-
retriever_sequence = (
|
1695 |
-
retriever_button.click(fn=stop_audio, inputs=[], outputs=[audio_output], api_name="api_stop_audio_recording")
|
1696 |
-
.then(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input], api_name="api_addprompt_chathistory")
|
1697 |
-
.then(fn=generate_bot_response_with_table, inputs=[chatbot, choice, retrieval_mode, model_choice], outputs=[chatbot, table_output], api_name="api_generate_bot_response_with_table")
|
1698 |
-
.then(fn=generate_tts_response, inputs=[chatbot, tts_choice], outputs=[audio_output], api_name="api_generate_tts_response")
|
1699 |
-
.then(fn=clear_textbox, inputs=[], outputs=[chat_input], api_name="api_clear_textbox")
|
1700 |
-
)
|
1701 |
-
|
1702 |
-
chat_input.submit(fn=stop_audio, inputs=[], outputs=[audio_output], api_name="api_stop_audio_recording").then(
|
1703 |
-
fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input], api_name="api_addprompt_chathistory"
|
1704 |
-
).then(
|
1705 |
-
fn=generate_bot_response_with_table, inputs=[chatbot, choice, retrieval_mode, model_choice], outputs=[chatbot, table_output], api_name="api_generate_bot_response_with_table"
|
1706 |
-
).then(
|
1707 |
-
fn=generate_tts_response, inputs=[chatbot, tts_choice], outputs=[audio_output], api_name="api_generate_tts_response"
|
1708 |
-
).then(
|
1709 |
-
fn=clear_textbox, inputs=[], outputs=[chat_input], api_name="api_clear_textbox"
|
1710 |
-
)
|
1711 |
-
|
1712 |
demo.queue()
|
1713 |
demo.launch(show_error=True)
|
1714 |
|
1715 |
|
1716 |
|
1717 |
|
|
|
|
|
|
1481 |
"178041_000197000852_V2.pdf"
|
1482 |
]
|
1483 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1484 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1485 |
|
|
|
|
|
|
|
1486 |
|
1487 |
|
|
|
|
|
|
|
1488 |
|
|
|
|
|
1489 |
|
1490 |
+
with gr.Blocks(theme='gradio/soft') as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1491 |
|
1492 |
|
1493 |
+
with gr.Row():
|
1494 |
+
with gr.Column():
|
1495 |
+
state = gr.State()
|
1496 |
|
1497 |
+
# File dropdown
|
1498 |
+
# file_dropdown = gr.Dropdown(label="Select Document", choices=files_list, value=None)
|
1499 |
|
1500 |
+
chatbot = gr.Chatbot([], elem_id="RADAR:Channel 94.1", bubble_full_width=False)
|
1501 |
+
choice = gr.Radio(label="Select Style", choices=["Details", "Conversational"], value="Conversational",interactive=False,visible=False)
|
1502 |
+
retrieval_mode = gr.Radio(label="Retrieval Mode", choices=["VDB", "KGF"], value="VDB",interactive=False,visible=False)
|
1503 |
+
model_choice = gr.Dropdown(label="Choose Model", choices=["LM-2"], value="LM-2")
|
1504 |
|
1505 |
+
# Link the dropdown change to handle_model_choice_change
|
1506 |
+
model_choice.change(fn=handle_model_choice_change, inputs=model_choice, outputs=[retrieval_mode, choice, choice])
|
1507 |
|
1508 |
+
# gr.Markdown("<h1 style='color: red;'>Talk to RADAR</h1>", elem_id="voice-markdown")
|
1509 |
|
1510 |
+
chat_input = gr.Textbox(show_copy_button=True, interactive=True, show_label=False, label="ASK Radar !!!")
|
1511 |
+
tts_choice = gr.Radio(label="Select TTS System", choices=["Alpha", "Beta"], value="Alpha")
|
1512 |
|
1513 |
+
retriever_button = gr.Button("Retriever")
|
1514 |
|
1515 |
+
clear_button = gr.Button("Clear")
|
1516 |
+
clear_button.click(lambda: [None, None], outputs=[chat_input, state])
|
1517 |
|
1518 |
+
# gr.Markdown("<h1 style='color: red;'>Radar Map</h1>", elem_id="Map-Radar")
|
1519 |
+
# location_output = gr.HTML()
|
1520 |
+
audio_output = gr.Audio(interactive=False, autoplay=True)
|
1521 |
|
1522 |
+
def stop_audio():
|
1523 |
+
audio_output.stop()
|
1524 |
+
return None
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 |
+
retriever_sequence = (
|
1531 |
+
retriever_button.click(fn=stop_audio, inputs=[], outputs=[audio_output], api_name="api_stop_audio_recording")
|
1532 |
+
.then(fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input], api_name="api_addprompt_chathistory")
|
1533 |
+
# First, generate the bot response
|
1534 |
+
.then(fn=generate_bot_response, inputs=[chatbot, choice, retrieval_mode, model_choice], outputs=[chatbot], api_name="api_generate_bot_response")
|
1535 |
+
# Then, generate the TTS response based on the bot's response
|
1536 |
+
.then(fn=generate_tts_response, inputs=[chatbot, tts_choice], outputs=[audio_output], api_name="api_generate_tts_response")
|
1537 |
+
.then(fn=clear_textbox, inputs=[], outputs=[chat_input], api_name="api_clear_textbox")
|
1538 |
+
)
|
1539 |
|
1540 |
|
1541 |
|
|
|
1544 |
|
1545 |
|
1546 |
|
1547 |
+
chat_input.submit(fn=stop_audio, inputs=[], outputs=[audio_output], api_name="api_stop_audio_recording").then(
|
1548 |
+
fn=add_message, inputs=[chatbot, chat_input], outputs=[chatbot, chat_input], api_name="api_addprompt_chathistory"
|
1549 |
+
).then(
|
1550 |
+
# First, generate the bot response
|
1551 |
+
fn=generate_bot_response, inputs=[chatbot, choice, retrieval_mode, model_choice], outputs=[chatbot], api_name="api_generate_bot_response"
|
1552 |
+
).then(
|
1553 |
+
# Then, generate the TTS response based on the bot's response
|
1554 |
+
fn=generate_tts_response, inputs=[chatbot, tts_choice], outputs=[audio_output], api_name="api_generate_tts_response"
|
1555 |
+
).then(
|
1556 |
+
fn=clear_textbox, inputs=[], outputs=[chat_input], api_name="api_clear_textbox"
|
1557 |
+
)
|
1558 |
|
1559 |
|
1560 |
|
|
|
1562 |
|
1563 |
|
1564 |
|
1565 |
+
audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy', every=0.1)
|
1566 |
+
audio_input.stream(transcribe_function, inputs=[state, audio_input], outputs=[state, chat_input], api_name="api_voice_to_text")
|
1567 |
|
1568 |
+
# gr.Markdown("<h1 style='color: red;'>Example Prompts</h1>", elem_id="Example-Prompts")
|
1569 |
+
# gr.Examples(examples=examples, fn=insert_prompt,inputs=chat_input, outputs=chat_input)
|
1570 |
|
1571 |
+
# with gr.Column():
|
1572 |
+
# weather_output = gr.HTML(value=fetch_local_weather())
|
1573 |
+
# news_output = gr.HTML(value=fetch_local_news())
|
1574 |
+
# events_output = gr.HTML(value=fetch_local_events())
|
1575 |
|
1576 |
+
# with gr.Column():
|
1577 |
|
1578 |
|
1579 |
+
# # Call update_images during the initial load to display images when the interface appears
|
1580 |
+
# initial_images = update_images()
|
1581 |
|
1582 |
+
# # Displaying the images generated using Flux API directly
|
1583 |
+
# image_output_1 = gr.Image(value=initial_images[0], label="Image 1", elem_id="flux_image_1", width=400, height=400)
|
1584 |
+
# image_output_2 = gr.Image(value=initial_images[1], label="Image 2", elem_id="flux_image_2", width=400, height=400)
|
1585 |
+
# image_output_3 = gr.Image(value=initial_images[2], label="Image 3", elem_id="flux_image_3", width=400, height=400)
|
1586 |
|
1587 |
+
# # Refresh button to update images
|
1588 |
+
# refresh_button = gr.Button("Refresh Images")
|
1589 |
+
# refresh_button.click(fn=update_images, inputs=None, outputs=[image_output_1, image_output_2, image_output_3])
|
1590 |
|
1591 |
|
1592 |
|
|
|
1594 |
|
1595 |
|
1596 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1597 |
demo.queue()
|
1598 |
demo.launch(show_error=True)
|
1599 |
|
1600 |
|
1601 |
|
1602 |
|
1603 |
+
|
1604 |
+
|