File size: 2,249 Bytes
33080cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
import numpy as np
import gradio as gr
from z_generate import ServerlessInference

# STATIC TEXT DISPLAY
TXT_APP_DESCRIPTION = '''
Just another Retrieval Augmented Generation that also retrieves images
'''
TXT_SOURCE_DOC_DESCRIPTION = '''
Manually Downloaded as HTML files: 

1. https://en.wikipedia.org/wiki/MS_Dhoni
2. https://en.wikipedia.org/wiki/Jharkhand
2. https://en.wikipedia.org/wiki/Cricket_World_Cup
'''


# UI Interface
demo = gr.Blocks()

llm = ServerlessInference()

# Processing Functions
def update_response(query:str = "something"):
    return llm.test(query)
    
def update_gallery(text:str = "hell"):
    imgs = [
                ("http://www.marketingtool.online/en/face-generator/img/faces/avatar-1151ce9f4b2043de0d2e3b7826127998.jpg", "Some Description"),
                ("http://www.marketingtool.online/en/face-generator/img/faces/avatar-116b5e92936b766b7fdfc242649337f7.jpg", "Another Description")
            ]
    return imgs


def ask_bot(text):
    return update_response(text), update_gallery(text)

# UI Layout
with demo:
    gr.Markdown(TXT_APP_DESCRIPTION)

    with gr.Tabs():
        with gr.TabItem("Ask Bot"):
            with gr.Row(equal_height=True):
                with gr.Column(scale=3):
                    text_input = gr.Textbox(
                        label="You query here",
                        placeholder="What positions apart from crickter did Dhoni held?"
                    )
                with gr.Column(scale=1):
                    btn_generate = gr.Button("Generate Answer")

            with gr.Row():
                with gr.Column(scale=3):
                    text_output = gr.Textbox(label="Bot Response:", placeholder="Type in Query before I could answer")
                
                with gr.Column(scale=2): 
                    gallery = gr.Gallery(
                        label="Generated images", show_label=False, elem_id="gallery"
                        , columns=[3], rows=[1], object_fit="contain", height="auto"
                    )

            btn_generate.click(ask_bot, text_input, outputs=[text_output, gallery])



        ####
        with gr.TabItem("Source Documents"):
            gr.Markdown(TXT_SOURCE_DOC_DESCRIPTION)

demo.launch(debug=True)