File size: 1,261 Bytes
33fbb25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os, sys
from os.path import dirname as up

sys.path.append(os.path.abspath(os.path.join(up(__file__), os.pardir)))

from utils import *


df = pd.read_csv(CSV_FILE_PATH)

def gradio_interface(helper_function):
    def clear_fields(query, output):
        return "", ""

    with gr.Blocks() as demo:
        gr.Markdown("""
        <h1> Question and Answer Bot for World Happiness Report 2023 </h1>
        
        Only first 5 rows shown. To check out whole dataset:
        https://www.kaggle.com/datasets/ajaypalsinghlo/world-happiness-report-2023
        """)
        with gr.Row():
            with gr.Column():
                inputs = [gr.Dataframe(df, row_count=(5, "fixed"), max_rows=5, label="World Happiness Report 2023")]
                query = gr.Text(label="Ask question about one or more countries.", placeholder="Type your question here", lines=4)
                btn_submit = gr.Button("Submit")
            with gr.Column():
                output = gr.TextArea(label="Response to the query.", lines=18)
                btn_clear = gr.Button("Clear")
        btn_submit.click(helper_function, inputs=[query], outputs=[output])
        btn_clear.click(clear_fields, inputs=[query, output], outputs=[query, output])
    
    return demo