File size: 1,509 Bytes
30af771
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import table_load as tl
import comm


css="""
#col-container {max-width: 700px; margin-left: auto; margin-right: auto;}
"""

title = """
<div style="text-align: center;max-width: 700px;">
    <h1>Analyze your CSV</h1>
    <p style="text-align: center;">Please specify OpenAI Key before use</p>
</div>
"""


with gr.Blocks(css=css) as demo:
    with gr.Column(elem_id="col-container"):
        gr.HTML(title)
    with gr.Column():
            openai_key = gr.Textbox(label="You OpenAI API key", type="password")
            raw_table = gr.File(label="Load a table file (xls or csv)", file_types=['.csv, xlsx, xls'], type="file")
            with gr.Row():
                langchain_status = gr.Textbox(label="Status", placeholder="", interactive=False)
                load_table = gr.Button("Load table to langchain")

    chatbot = gr.Chatbot([], elem_id="chatbot").style(height=350)
    with gr.Column(scale=0.85):
        question = gr.Textbox(show_label=False, placeholder="Type your question and hit Enter").style(container=False)
    with gr.Column(scale=0.15, min_width=0):
        clr_btn = gr.Button("Clear History")
        
        
    load_table.click(tl.load_file, None, langchain_status, queue=False)    
    load_table.click(tl.table_loader, inputs=[raw_table, openai_key], outputs=[langchain_status], queue=False)
   
    question.submit(comm.respond, [question, chatbot], [question, chatbot])
    clr_btn.click(lambda: None, None, chatbot, queue=False)
    
demo.launch()