File size: 2,160 Bytes
67a91b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0e82628
67a91b0
 
 
 
0e82628
67a91b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20b77a1
67a91b0
 
 
 
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
import os
from typing import Dict, List
import gradio as gr
from src.main import get_response, add_file
from dotenv import load_dotenv

load_dotenv("./.env")
print(os.environ)

def process_input(message: str, history: List):
    response = get_response(message)
    history.append((message, response["answer"]))
    return (
        "",
        history,
        "\n".join([res.metadata["source"] for res in response["source_documents"]]),
    )


def add_to_db(file: gr.File):
    add_file(file)
    gr.Info("File added to Vector Database")


def main():
    with gr.Blocks(title="Alialhajri Chat PPG", theme="soft") as demo:
        gr.HTML(
            """
            <div style="display: flex; flex-direction: column; align-items: center; text-align: center; margin-top: 10px;">
                <div style="width: 100px; height: 100px; border-radius: 50%; overflow: hidden;">
                <img src="/file=static/icon_2.jpg" alt="Hospital Icon" style="width: 100%; height: 100%; object-fit: cover;">
            </div>
            <div style="margin-top: 5px; font-size:24px; font-weight: bold;">Hospital Policy</div>
            </div>
            """
        )
        with gr.Tabs():
            with gr.Tab(label="Chatbot"):
                chatbot = gr.Chatbot(height=300, likeable=True)
                message = gr.Textbox(
                    placeholder="Ask me a yes or no question",
                    scale=7,
                    label="Input message",
                )
                sources = gr.Textbox(label="Sources")
                _ = gr.ClearButton([message, chatbot, sources])

                message.submit(
                    process_input,
                    inputs=[message, chatbot],
                    outputs=[message, chatbot, sources],
                )
            # with gr.Tab(label="Add Data"):
            #     upload_file = gr.File(label="Upload file(PDF, DOCX, Image)")
            #     upload_file_button = gr.Button(value="Add File to Vector DB")

            # upload_file_button.click(add_to_db, inputs=upload_file)

    demo.launch(allowed_paths=["static", "."])


if __name__ == "__main__":
    main()