File size: 4,115 Bytes
30ef6e4
 
 
 
 
9a6771d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30ef6e4
 
9a6771d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30ef6e4
 
 
9a6771d
 
30ef6e4
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import fn
import gradio as gr

with gr.Blocks() as demo:
    gr.Markdown('# vector_search')
    info = gr.Markdown()

    with gr.Tab('ddg'):
        ddg_query = gr.Textbox(
            lines=1,
            label='Query',
            interactive=True,
            show_copy_button=True,
            )
        ddg_button = gr.Button(
            variant='primary',
            value='Search',
            )
        ddg_result = gr.Textbox(
            lines=20,
            label='Result',
            interactive=True,
            show_copy_button=True,
            )

    with gr.Tab('bs4'):
        bs4_url = gr.Textbox(
            lines=1,
            label='URL',
            interactive=True,
            show_copy_button=True,
            )
        bs4_button = gr.Button(
            variant='primary',
            value='Scraping',
            )
        bs4_result = gr.Textbox(
            lines=20,
            label='Result',
            interactive=True,
            show_copy_button=True,
            )

    with gr.Tab('upload'):
        gr.Markdown('name単位でsearchできます。行ごとにchunkになります。')
        upload_name = gr.Textbox(
            lines=1,
            label='Name',
            interactive=True,
            show_copy_button=True,
            )
        upload_filename = gr.Textbox(
            lines=1,
            label='FileName',
            interactive=True,
            show_copy_button=True,
            )
        upload_content = gr.Textbox(
            lines=20,
            label='Content',
            interactive=True,
            show_copy_button=True,
            )
        upload_button = gr.Button(
            variant='primary',
            value='Upload',
            )

    with gr.Tab('delete'):
        delete_name = gr.Textbox(
            lines=1,
            label='Name',
            interactive=True,
            show_copy_button=True,
            )
        delete_filename = gr.Textbox(
            lines=1,
            label='FileName',
            interactive=True,
            show_copy_button=True,
            )
        delete_button = gr.Button(
            variant='primary',
            value='Delete',
            )

    with gr.Tab('embedding'):
        gr.Markdown('データベースを更新します。')
        embedding_button = gr.Button(
            variant='primary',
            value='Embedding',
            )
        gr.Markdown('メモリのデータベースを再読み込みします。')
        reload_button = gr.Button(
            variant='primary',
            value='Reload',
            )

    with gr.Tab('search'):
        search_name = gr.Textbox(
            lines=1,
            label='Name',
            interactive=True,
            show_copy_button=True,
            )
        search_query = gr.Textbox(
            lines=1,
            label='Query',
            interactive=True,
            show_copy_button=True,
            )
        search_button = gr.Button(
            variant='primary',
            value='Search',
            )
        search_result = gr.Textbox(
            label='Result',
            lines=20,
            interactive=True,
            show_copy_button=True,
            )

    ddg_button.click(
        fn=fn.ddg,
        inputs=[ddg_query],
        outputs=[ddg_result],
        )

    bs4_button.click(
        fn=fn.bs4,
        inputs=[bs4_url],
        outputs=[bs4_result],
        )

    upload_button.click(
        fn=fn.upload,
        inputs=[upload_name, upload_filename, upload_content],
        outputs=[info],
        )

    delete_button.click(
        fn=fn.delete,
        inputs=[delete_name, delete_filename],
        outputs=[info],
        )

    embedding_button.click(
        fn=fn.embedding,
        inputs=[],
        outputs=[info],
        )

    reload_button.click(
        fn=fn.load_vectors,
        inputs=[],
        outputs=[info],
        )

    search_button.click(
        fn=fn.search,
        inputs=[search_name, search_query],
        outputs=[search_result],
        )

if __name__ == '__main__':
    demo.launch()