Spaces:
Sleeping
Sleeping
File size: 2,047 Bytes
2a43a55 b7cfea3 2a43a55 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
import random
import time
import gradio as gr
from matt_function import create_VSI
logo_filepath = 'Readable.png'
robot_filepath = 'Robot.png'
custom_css = """
.column {
align-items: center;
}
.column_el {
flex-grow: 1;
}
"""
def respond(message, chat_history, index):
bot_message = index.query(message)
chat_history.append((message, bot_message.response))
return "", chat_history, display_question_and_answer(chat_history)
def display_question_and_answer(tuple_list):
qa_history = ""
for i, (q, a) in enumerate(tuple_list):
qa_history += f"<details><summary>Q: {q}</summary><p>A: {a}</p></details>"
return qa_history
with gr.Blocks(css=custom_css) as demo:
with gr.Tab("Home"):
with gr.Row(variant='compact'):
with gr.Column(scale=1, elem_classes='column'):
logo = gr.Image(value=logo_filepath, type='filepath', show_label=False, show_download_button=False, container=False, elem_classes='column_el')
VSidx = gr.State()
files = gr.File(file_count='multiple', show_label=False, elem_classes='column_el', height=75)
# name = gr.Textbox(label="Name", elem_classes='column_el')
# description = gr.Textbox(label="Description", elem_classes='column_el')
create_VSI_btn = gr.Button(value='Submit', elem_classes='column_el')
upload_status = gr.Textbox(label='Upload Status', value='No PDF uploaded')
create_VSI_btn.click(fn=create_VSI, inputs = [files, VSidx], outputs = [VSidx, upload_status])
robot = gr.Image(value=robot_filepath, type='filepath', show_label=False, show_download_button=False, container=False, width=125, height=125, elem_classes='column_el')
with gr.Column(scale=3, elem_classes='column'):
chatbot = gr.Chatbot(elem_classes='column_el')
msg = gr.Textbox(show_label=False, elem_classes='column_el')
with gr.Tab("Chat History"):
history = gr.HTML()
msg.submit(respond, [msg, chatbot, VSidx], [msg, chatbot, history])
demo.launch()
|