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